try {
if(contentlet.getInode().equals(""))
throw new DotContentletStateException(CAN_T_CHANGE_STATE_OF_CHECKED_OUT_CONTENT);
if(!perAPI.doesUserHavePermission(contentlet, PermissionAPI.PERMISSION_EDIT, user, respectFrontendRoles)){
throw new DotSecurityException("User: " + (user != null ? user.getUserId() : "Unknown")
+ " does not have permission to edit the contentlet");
}
Contentlet workingContentlet = findContentletByIdentifier(contentlet.getIdentifier(), false, contentlet.getLanguageId(), user, respectFrontendRoles);
Contentlet liveContentlet = null;
try{
liveContentlet = findContentletByIdentifier(contentlet.getIdentifier(), true, contentlet.getLanguageId(), user, respectFrontendRoles);
}catch (DotContentletStateException ce) {
Logger.debug(this,"No live contentlet found for identifier = " + contentlet.getIdentifier());
}
canLock(contentlet, user);
User modUser = null;
try{
modUser = APILocator.getUserAPI().loadUserById(workingContentlet.getModUser(),APILocator.getUserAPI().getSystemUser(),false);
}catch(Exception ex){
if(ex instanceof NoSuchUserException){
modUser = APILocator.getUserAPI().getSystemUser();
}
}
if(modUser != null){
workingContentlet.setModUser(modUser.getUserId());
}
if (user == null || !workingContentlet.isLocked() || workingContentlet.getModUser().equals(user.getUserId())) {
if (liveContentlet != null && InodeUtils.isSet(liveContentlet.getInode())) {
APILocator.getVersionableAPI().removeLive(liveContentlet);
indexAPI.removeContentFromLiveIndex(liveContentlet);
}
// sets deleted to true
APILocator.getVersionableAPI().setDeleted(workingContentlet, true);
// Updating lucene index
indexAPI.addContentToIndex(workingContentlet);
if(contentlet.getStructure().getStructureType()==Structure.STRUCTURE_TYPE_FILEASSET) {
Identifier ident = APILocator.getIdentifierAPI().find(contentlet);
CacheLocator.getCSSCache().remove(ident.getHostId(), ident.getPath(), true);
CacheLocator.getCSSCache().remove(ident.getHostId(), ident.getPath(), false);
}
ContentletServices.invalidate(contentlet);
ContentletMapServices.invalidate(contentlet);
publishRelatedHtmlPages(contentlet);
}else{
throw new DotContentletStateException("Contentlet is locked: Unable to archive");
}
} catch(DotDataException | DotStateException| DotSecurityException e) {
ActivityLogger.logInfo(getClass(), "Error Archiving Content", "StartDate: " +contentPushPublishDate+ "; "
+ "EndDate: " +contentPushExpireDate + "; User:" + (user != null ? user.getUserId() : "Unknown")