}
public static MediumContentVersionImpl changeState(Integer oldContentVersionId, ContentVO contentVO, Integer stateId, String versionComment, boolean overrideVersionModifyer, String recipientFilter, InfoGluePrincipal infoGluePrincipal, Integer contentId, Database db, List resultingEvents, Integer excludedAssetId) throws SystemException, ConstraintException
{
Timer t = new Timer();
MediumContentVersionImpl newContentVersion = null;
try
{
MediumContentVersionImpl oldContentVersion = ContentVersionController.getContentVersionController().getReadOnlyMediumContentVersionWithId(oldContentVersionId, db);
newContentVersion = oldContentVersion;
logger.info("oldContentVersion:" + oldContentVersion.getId());
//t.printElapsedTime("oldContentVersion");
if (contentId == null && contentVO != null)
contentId = contentVO.getContentId();
else if(contentId == null)
contentId = oldContentVersion.getValueObject().getContentId();
if(contentId != null && contentVO == null)
contentVO = ContentController.getContentController().getContentVOWithId(contentId, db);
boolean duplicateAssets = CmsPropertyHandler.getDuplicateAssetsBetweenVersions();
//Here we create a new version if it was a state-change back to working, it's a copy of the publish-version
if (stateId.intValue() == ContentVersionVO.WORKING_STATE.intValue())
{
logger.info("About to create a new working version");
ContentVersionVO newContentVersionVO = new ContentVersionVO();
newContentVersionVO.setStateId(stateId);
if(versionComment != null && !versionComment.equals(""))
newContentVersionVO.setVersionComment(versionComment);
else
newContentVersionVO.setVersionComment("New working version");
newContentVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
if(overrideVersionModifyer)
newContentVersionVO.setVersionModifier(infoGluePrincipal.getName());
else
newContentVersionVO.setVersionModifier(oldContentVersion.getVersionModifier());
newContentVersionVO.setVersionValue(oldContentVersion.getVersionValue());
newContentVersion = ContentVersionController.getContentVersionController().createMedium(oldContentVersion, contentId, oldContentVersion.getValueObject().getLanguageId(), newContentVersionVO, oldContentVersion.getContentVersionId(), (oldContentVersion.getDigitalAssets().size() > 0), true, duplicateAssets, excludedAssetId, db);
//newContentVersion = ContentVersionController.getContentVersionController().create(contentId, oldContentVersion.getLanguage().getLanguageId(), newContentVersionVO, oldContentVersion.getContentVersionId(), true, duplicateAssets, excludedAssetId, db);
//ContentVersionController.getContentVersionController().copyDigitalAssets(oldContentVersion, newContentVersion, db);
if(contentVO.getIsProtected().equals(ContentVO.YES))
copyAccessRights(oldContentVersion.getId(), newContentVersion.getId(), db);
copyContentCategories(oldContentVersion.getId(), newContentVersion.getId(), db);
RegistryController.getController().updateContentVersionThreaded(newContentVersion.getValueObject(), null);
}
//If the user changes the state to publish we create a copy and set that copy to publish.
if (stateId.intValue() == ContentVersionVO.PUBLISH_STATE.intValue())
{
logger.info("About to copy the working copy to a publish-one");
//First we update the old working-version so it gets a comment
logger.info("Setting comment " + versionComment + " on " + oldContentVersion.getId());
//oldContentVersion.setVersionComment(versionComment);
if(CmsPropertyHandler.getUseApprovalFlow().equals("true"))
{
//Now we create a new version which is basically just a copy of the working-version
ContentVersionVO newContentVersionVO = new ContentVersionVO();
newContentVersionVO.setStateId(stateId);
newContentVersionVO.setVersionComment(versionComment);
newContentVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
if(overrideVersionModifyer)
newContentVersionVO.setVersionModifier(infoGluePrincipal.getName());
else
newContentVersionVO.setVersionModifier(oldContentVersion.getVersionModifier());
newContentVersionVO.setVersionValue(oldContentVersion.getVersionValue());
newContentVersion = ContentVersionController.getContentVersionController().createMedium(oldContentVersion, contentId, oldContentVersion.getValueObject().getLanguageId(), newContentVersionVO, oldContentVersion.getContentVersionId(), (oldContentVersion.getDigitalAssets().size() > 0), false, duplicateAssets, excludedAssetId, db);
logger.info("Creating " + newContentVersion.getId());
//ContentVersionController.getContentVersionController().copyDigitalAssets(oldContentVersion, newContentVersion, db);
if(contentVO.getIsProtected().equals(ContentVO.YES))
copyAccessRights(oldContentVersion.getId(), newContentVersion.getId(), db);
copyContentCategories(oldContentVersion.getId(), newContentVersion.getId(), db);
//Creating the event that will notify the editor...
RegistryController.getController().updateContentVersionThreaded(newContentVersion.getValueObject(), null);
ContentTypeDefinitionVO metaInfoCTDVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info");
if(contentVO.getContentTypeDefinitionId() != null && !contentVO.getContentTypeDefinitionId().equals(metaInfoCTDVO.getId()))
{
EventVO eventVO = new EventVO();
eventVO.setDescription(newContentVersion.getVersionComment());
eventVO.setEntityClass(ContentVersion.class.getName());
eventVO.setEntityId(new Integer(newContentVersion.getId().intValue()));
eventVO.setName(contentVO.getName());
eventVO.setTypeId(EventVO.PUBLISH);
eventVO = EventController.create(eventVO, contentVO.getRepositoryId(), infoGluePrincipal, db);
resultingEvents.add(eventVO);
}
}
else
{
oldContentVersion = ContentVersionController.getContentVersionController().getMediumContentVersionWithId(oldContentVersionId, db);
oldContentVersion.setVersionComment(versionComment);
EventVO eventVO = new EventVO();
eventVO.setDescription(versionComment);
eventVO.setEntityClass(ContentVersion.class.getName());
eventVO.setEntityId(new Integer(newContentVersion.getId().intValue()));
eventVO.setName(contentVO.getName());
eventVO.setTypeId(EventVO.PUBLISH);
eventVO = EventController.create(eventVO, contentVO.getRepositoryId(), infoGluePrincipal, db);
resultingEvents.add(eventVO);
}
//if(recipientFilter != null && !recipientFilter.equals(""))
// PublicationController.mailPublishNotification(resultingEvents, contentVO.getRepositoryId(), infoGluePrincipal, recipientFilter, db);
}
//If the user in the publish-app publishes a publish-version we change state to published.
if (stateId.intValue() == ContentVersionVO.PUBLISHED_STATE.intValue())
{
oldContentVersion = ContentVersionController.getContentVersionController().getMediumContentVersionWithId(oldContentVersionId, db);
logger.info("About to publish an existing version:" + oldContentVersion.getId() + ":" + oldContentVersion.getStateId());
Integer oldContentVersionStateId = oldContentVersion.getStateId();
oldContentVersion.setStateId(stateId);
oldContentVersion.setIsActive(new Boolean(true));
//New logic to add meta data in some cases... ugly but needed if users are removed.
insertIGMetaDataAttributes(oldContentVersion, infoGluePrincipal);
//End new logic