ConstraintExceptionBuffer ceb = contentVersionVO.validateAdvanced(contentTypeDefinitionVO, languageCode);
logger.info("Skipping validate:" + skipValidate);
if(!skipValidate)
ceb.throwIfNotEmpty();
MediumContentVersionImpl contentVersion = null;
Integer contentVersionIdToUpdate = contentVersionVO.getId();
contentVersionVO.setModifiedDateTime(new Date());
if(contentVersionVO.getId() == null)
{
logger.info("Creating the entity because there was no version at all for: " + contentId + " " + languageId);
contentVersion = createMedium(contentId, languageId, contentVersionVO, db);
}
else
{
ContentVersionVO oldContentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(contentVersionVO.getId(), db);
ContentVersionVO latestContentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(oldContentVersionVO.getContentId(), oldContentVersionVO.getLanguageId(), db);
if(!oldContentVersionVO.getStateId().equals(ContentVersionVO.WORKING_STATE) && !latestContentVersionVO.getStateId().equals(ContentVersionVO.WORKING_STATE))
{
List<EventVO> events = new ArrayList<EventVO>();
contentVersion = ContentStateController.changeState(oldContentVersionVO.getId(), contentVO, ContentVersionVO.WORKING_STATE, (contentVersionVO.getVersionComment().equals("No comment") ? "new working version" : contentVersionVO.getVersionComment()), false, null, principal, oldContentVersionVO.getContentId(), db, events);
contentVersion.setVersionValue(contentVersionVO.getVersionValue());
/*
List<String> changedAttributes = getChangedAttributeNames(oldContentVersionVO, contentVersionVO);
System.out.println("changedAttributes in contentversioncontroller:" + changedAttributes);
Map extraInfoMap = new HashMap();
String csList = StringUtils.join(changedAttributes.toArray(), ",");
extraInfoMap.put("changedAttributeNames", csList);
CacheController.setExtraInfo(ContentVersionImpl.class.getName(), contentVersion.getId().toString(), extraInfoMap);
*/
}
else
{
if(latestContentVersionVO.getStateId().equals(ContentVersionVO.WORKING_STATE))
{
oldContentVersionVO = contentVersionVO;
contentVersionIdToUpdate = latestContentVersionVO.getId();
}
List<String> changedAttributes = getChangedAttributeNames(oldContentVersionVO, contentVersionVO);
Map<String,String> extraInfoMap = new HashMap<String,String>();
String csList = StringUtils.join(changedAttributes.toArray(), ",");
//logger.info("csList:" + csList);
extraInfoMap.put("changedAttributeNames", csList);
CacheController.setExtraInfo(ContentVersionImpl.class.getName(), contentVersionVO.getId().toString(), extraInfoMap);
contentVersion = ContentVersionController.getContentVersionController().getMediumContentVersionWithId(contentVersionIdToUpdate, db);
//contentVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
Integer existingContentId = contentVersion.getValueObject().getContentId();
contentVersionVO.setContentId(existingContentId);
contentVersionVO.setLanguageId(contentVersion.getValueObject().getLanguageId());
contentVersion.setValueObject(contentVersionVO);
contentVersion.setContentVersionId(contentVersionIdToUpdate);
contentVersion.setStateId(ContentVersionVO.WORKING_STATE);
}
}
SiteNodeVersionVO latestSiteNodeVersionVO = null;
if(principal != null && contentTypeDefinitionVO.getName().equalsIgnoreCase("Meta info") && !skipSiteNodeVersionUpdate)
{
SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithMetaInfoContentId(db, contentId);
//SiteNode siteNode = SiteNodeController.getController().getSiteNodeWithMetaInfoContentId(db, contentId);
if(siteNodeVO.getMetaInfoContentId() != null && siteNodeVO.getMetaInfoContentId().equals(contentId))
{
latestSiteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(db, siteNodeVO.getId());
latestSiteNodeVersionVO.setVersionModifier(contentVersionVO.getVersionModifier());
latestSiteNodeVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().acUpdate(principal, latestSiteNodeVersionVO, db);
Map extraInfoMap = new HashMap();
extraInfoMap.put("skipSiteNodeVersionUpdate", "true");
// extraInfoMap.put("contentId", ""+contentVO.getId());
// extraInfoMap.put("parentContentId", ""+contentVO.getParentContentId());
// extraInfoMap.put("repositoryId", ""+contentVO.getRepositoryId());
CacheController.setExtraInfo(SiteNodeVersionImpl.class.getName(), latestSiteNodeVersionVO.getId().toString(), extraInfoMap);
}
}
registryController.updateContentVersionThreaded(contentVersion.getValueObject(), latestSiteNodeVersionVO);
updatedContentVersionVO = contentVersion.getValueObject();
return updatedContentVersionVO;
}