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 /** Constants for attribute 'computedMicroSkills' */ 044 public static final String COMPUTED_MICRO_SKILLS = "computedMicroSkills"; 045 046 /** 047 * Constructor. 048 * @param node the JCR Node backing this Content. 049 * @param parentPath the parent path in the Ametys hierarchy. 050 * @param factory the corresponding {@link ProgramFactory}. 051 */ 052 public Program(Node node, String parentPath, ProgramFactory factory) 053 { 054 super(node, parentPath, factory); 055 } 056 057 @Override 058 public List<ProgramPart> getProgramPartParents() 059 { 060 return Collections.EMPTY_LIST; 061 } 062 063 // --------------------------------------------------------------------------------------// 064 // CDMfr 065 // --------------------------------------------------------------------------------------// 066 @Override 067 public String getCDMTagName() 068 { 069 return CDMFRTagsConstants.TAG_PROGRAM; 070 } 071 072 /** 073 * Get the degree 074 * @return the degree or null 075 */ 076 public String getDegree() 077 { 078 try 079 { 080 return ContentDataHelper.getContentIdFromContentData(this, DEGREE); 081 } 082 catch (UndefinedItemPathException e) 083 { 084 return null; // this attribute is not part of model 085 } 086 } 087 088 /** 089 * Get the acquired skills 090 * @return the acquired skills 091 */ 092 public List<Content> getSkills() 093 { 094 try 095 { 096 return Arrays.stream(getValueOrDefault(SKILLS, new ContentValue[0])) 097 .map(ContentValue::getContentIfExists) 098 .flatMap(Optional::stream) 099 .collect(Collectors.toList()); 100 } 101 catch (UndefinedItemPathException e) 102 { 103 return List.of(); // this attribute is not part of model, skills are not enabled 104 } 105 } 106 107 /** 108 * Get the acquired transversal skills 109 * @return the acquired transversal skills 110 */ 111 public List<Content> getTransversalSkills() 112 { 113 try 114 { 115 return Arrays.stream(getValueOrDefault(TRANSVERSAL_SKILLS, new ContentValue[0])) 116 .map(ContentValue::getContentIfExists) 117 .flatMap(Optional::stream) 118 .collect(Collectors.toList()); 119 } 120 catch (UndefinedItemPathException e) 121 { 122 return List.of(); // this attribute is not part of model, skills are not enabled 123 } 124 } 125}