001/* 002 * Copyright 2012 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.odf.program; 017 018import java.util.Arrays; 019import java.util.Collections; 020import java.util.List; 021import java.util.Optional; 022import java.util.stream.Collectors; 023 024import javax.jcr.Node; 025 026import org.ametys.cms.data.ContentDataHelper; 027import org.ametys.cms.data.ContentValue; 028import org.ametys.cms.repository.Content; 029import org.ametys.odf.cdmfr.CDMFRTagsConstants; 030import org.ametys.runtime.model.exception.UndefinedItemPathException; 031 032/** 033 * This class represent the root element of a program 034 */ 035public class Program extends AbstractProgram<ProgramFactory> 036{ 037 /** Constants for attribute 'skills' */ 038 public static final String SKILLS = "skills"; 039 /** Constants for attribute 'transversalSkills' */ 040 public static final String TRANSVERSAL_SKILLS = "transversalSkills"; 041 /** Constants for attribute 'blockingMicroSkills' */ 042 public static final String BLOCKING_SKILLS = "blockingMicroSkills"; 043 044 /** 045 * Constructor. 046 * @param node the JCR Node backing this Content. 047 * @param parentPath the parent path in the Ametys hierarchy. 048 * @param factory the corresponding {@link ProgramFactory}. 049 */ 050 public Program(Node node, String parentPath, ProgramFactory factory) 051 { 052 super(node, parentPath, factory); 053 } 054 055 @Override 056 public List<ProgramPart> getProgramPartParents() 057 { 058 return Collections.EMPTY_LIST; 059 } 060 061 // --------------------------------------------------------------------------------------// 062 // CDMfr 063 // --------------------------------------------------------------------------------------// 064 @Override 065 public String getCDMTagName() 066 { 067 return CDMFRTagsConstants.TAG_PROGRAM; 068 } 069 070 /** 071 * Get the degree 072 * @return the degree or null 073 */ 074 public String getDegree() 075 { 076 try 077 { 078 return ContentDataHelper.getContentIdFromContentData(this, DEGREE); 079 } 080 catch (UndefinedItemPathException e) 081 { 082 return null; // this attribute is not part of model 083 } 084 } 085 086 /** 087 * Get the acquired skills 088 * @return the acquired skills 089 */ 090 public List<Content> getSkills() 091 { 092 try 093 { 094 return Arrays.stream(getValue(SKILLS, false, new ContentValue[0])) 095 .map(ContentValue::getContentIfExists) 096 .flatMap(Optional::stream) 097 .collect(Collectors.toList()); 098 } 099 catch (UndefinedItemPathException e) 100 { 101 return List.of(); // this attribute is not part of model, skills are not enabled 102 } 103 } 104 105 /** 106 * Get the acquired transversal skills 107 * @return the acquired transversal skills 108 */ 109 public List<Content> getTransversalSkills() 110 { 111 try 112 { 113 return Arrays.stream(getValue(TRANSVERSAL_SKILLS, false, new ContentValue[0])) 114 .map(ContentValue::getContentIfExists) 115 .flatMap(Optional::stream) 116 .collect(Collectors.toList()); 117 } 118 catch (UndefinedItemPathException e) 119 { 120 return List.of(); // this attribute is not part of model, skills are not enabled 121 } 122 } 123}