public ContentVersionVO update(Integer contentId, Integer languageId, ContentVersionVO contentVersionVO, InfoGluePrincipal principal, boolean skipValidate, Database db, boolean skipSiteNodeVersionUpdate) throws Exception
{
ContentVersionVO updatedContentVersionVO;
ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId, db);
ContentTypeDefinitionVO contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(contentVO.getContentTypeDefinitionId(), db);
String languageCode = null;
if(principal != null && principal.getName() != null)
languageCode = CmsPropertyHandler.getPreferredLanguageCode(principal.getName());
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))
{