1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 import org.apache.log4j.Logger; 29 import org.infoglue.cms.applications.workflowtool.util.ContentFactory; 30 import org.infoglue.cms.applications.workflowtool.util.ContentValues; 31 import org.infoglue.cms.applications.workflowtool.util.ContentVersionValues; 32 import org.infoglue.cms.entities.content.ContentVO; 33 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO; 34 import org.infoglue.cms.entities.management.LanguageVO; 35 import org.infoglue.cms.exception.ConstraintException; 36 37 import com.opensymphony.workflow.WorkflowException; 38 39 42 public class ContentCreator extends ContentFunction 43 { 44 private final static Logger logger = Logger.getLogger(ContentCreator.class.getName()); 45 46 49 public static final String FOLDER_PARAMETER = "create_folder"; 50 51 54 private static final String STATUS_OK = "status.content.ok"; 55 56 59 private static final String STATUS_NOK = "status.content.nok"; 60 61 64 private LanguageVO languageVO; 65 66 69 private ContentTypeDefinitionVO contentTypeDefinitionVO; 70 71 74 private Map categories; 75 76 79 private ContentValues contentValues; 80 81 84 private ContentVersionValues contentVersionValues; 85 86 89 private ContentVO parentFontentVO; 90 91 92 95 protected void execute() throws WorkflowException 96 { 97 setFunctionStatus(STATUS_NOK); 98 try 99 { 100 final ContentFactory factory = new ContentFactory(contentTypeDefinitionVO, contentValues, contentVersionValues, getPrincipal(), languageVO); 101 ContentVO newContentVO = null; 102 if(getContentVO() == null) 103 { 104 parentFontentVO = (ContentVO) getParameter(FOLDER_PARAMETER); 105 newContentVO = factory.create(parentFontentVO, categories, getDatabase()); 106 } 107 else 108 { 109 newContentVO = factory.update(getContentVO(), categories, getDatabase()); 110 } 111 if(newContentVO != null) 112 { 113 setPropertySetString(ContentProvider.CONTENT_ID_PROPERTYSET_KEY, newContentVO.getContentId().toString()); 114 } 115 setFunctionStatus((newContentVO != null) ? STATUS_OK : STATUS_NOK); 116 } 117 catch(ConstraintException e) 118 { 119 logger.debug(e.toString()); 120 } 121 catch(Exception e) 122 { 123 throwException(e); 124 } 125 } 126 127 133 protected void initialize() throws WorkflowException 134 { 135 super.initialize(); 136 contentTypeDefinitionVO = (ContentTypeDefinitionVO) getParameter(ContentTypeDefinitionProvider.CONTENT_TYPE_DEFINITION_PARAMETER); 137 languageVO = (LanguageVO) getParameter(LanguageProvider.LANGUAGE_PARAMETER); 138 categories = (Map ) getParameter(CategoryProvider.CATEGORIES_PARAMETER, new HashMap ()); 139 contentValues = (ContentValues) getParameter(ContentPopulator.CONTENT_VALUES_PARAMETER); 140 contentVersionValues = (ContentVersionValues) getParameter(ContentPopulator.CONTENT_VERSION_VALUES_PARAMETER); 141 } 142 } 143 | Popular Tags |