From e4d6eacb45892a12aa1b99e877df4a8aa48f6b12 Mon Sep 17 00:00:00 2001 From: Jose Castro Date: Fri, 12 May 2017 12:24:18 -0600 Subject: [PATCH] #11071 : Adding new date format that includes the seconds parameter. Removing unnecessary comment lines. Adding/fixing Javadoc. --- .../business/ESContentletAPIImpl.java | 176 +++++++----------- 1 file changed, 64 insertions(+), 112 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java b/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java index f15fd506e277..13febd87a920 100644 --- a/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java @@ -1,6 +1,3 @@ -/** - * - */ package com.dotcms.content.elasticsearch.business; import java.io.BufferedOutputStream; @@ -26,14 +23,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.dotcms.api.system.event.*; -import com.dotmarketing.cache.ContentTypeCache; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.springframework.beans.BeanUtils; +import com.dotcms.api.system.event.ContentletSystemEventUtil; import com.dotcms.content.business.DotMappingException; import com.dotcms.contenttype.model.field.CategoryField; import com.dotcms.contenttype.model.field.ConstantField; @@ -44,8 +40,6 @@ import com.dotcms.publisher.business.PublisherAPI; import com.dotcms.repackage.com.google.common.collect.Lists; import com.dotcms.repackage.com.google.common.collect.Maps; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.dotcms.repackage.com.thoughtworks.xstream.XStream; import com.dotcms.repackage.com.thoughtworks.xstream.io.xml.DomDriver; import com.dotcms.repackage.org.apache.commons.io.FileUtils; @@ -69,7 +63,6 @@ import com.dotmarketing.business.query.QueryUtil; import com.dotmarketing.business.query.ValidationException; import com.dotmarketing.cache.FieldsCache; - import com.dotmarketing.common.business.journal.DistributedJournalAPI; import com.dotmarketing.common.db.DotConnect; import com.dotmarketing.common.model.ContentletSearch; @@ -111,7 +104,6 @@ import com.dotmarketing.portlets.languagesmanager.model.Language; import com.dotmarketing.portlets.links.model.Link; import com.dotmarketing.portlets.structure.business.FieldAPI; - import com.dotmarketing.portlets.structure.model.ContentletRelationships; import com.dotmarketing.portlets.structure.model.ContentletRelationships.ContentletRelationshipRecords; import com.dotmarketing.portlets.structure.model.Field; @@ -141,6 +133,8 @@ import com.dotmarketing.util.UUIDGenerator; import com.dotmarketing.util.UtilMethods; import com.dotmarketing.util.WebKeys; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.liferay.portal.NoSuchUserException; import com.liferay.portal.model.User; import com.liferay.util.FileUtil; @@ -155,13 +149,10 @@ */ public class ESContentletAPIImpl implements ContentletAPI { - - private static final String CAN_T_CHANGE_STATE_OF_CHECKED_OUT_CONTENT = "Can't change state of checked out content or where inode is not set. Use Search or Find then use method"; private static final String CANT_GET_LOCK_ON_CONTENT ="Only the CMS Admin or the user who locked the contentlet can lock/unlock it"; private ESContentletIndexAPI indexAPI; - private ContentTypeCache contentTypeCache; private ESContentFactoryImpl conFac; private PermissionAPI perAPI; private CategoryAPI catAPI; @@ -182,7 +173,7 @@ public static enum QueryType { }; /** - * + * Default class constructor. */ public ESContentletAPIImpl () { indexAPI = new ESContentletIndexAPI(); @@ -505,7 +496,6 @@ public void publishAssociated(Contentlet contentlet, boolean isNew, boolean isNe // writes the contentlet object to a file indexAPI.addContentToIndex(contentlet, true, true); - // DOTCMS - 4393 // Publishes the files associated with the Contentlet List fields = FieldsCache.getFieldsByStructureInode(contentlet.getStructureInode()); Language defaultLang = lanAPI.getDefaultLanguage(); @@ -515,8 +505,6 @@ public void publishAssociated(Contentlet contentlet, boolean isNew, boolean isNe if (Field.FieldType.IMAGE.toString().equals(field.getFieldType()) || Field.FieldType.FILE.toString().equals(field.getFieldType())) { - // I know! You already saw the nested try/catch blocks below, - // please don't shoot the messenger, let me explain. // NOTE: Keep in mind that at this moment the FILE ASSET could be in the same language or // default lang (DEFAULT_FILE_TO_DEFAULT_LANGUAGE=true) try { @@ -658,7 +646,7 @@ public List searchByIdentifier(String luceneQuery, int limit, int of identifiers=identifierList.toArray(identifiers); List contentlets = new ArrayList(); - if(anyLanguage){//GIT-816 + if(anyLanguage){ for(String identifier : identifiers){ for(Language lang : APILocator.getLanguageAPI().getLanguages()){ try{ @@ -841,8 +829,6 @@ public void cleanField(Structure structure, Field field, User user, boolean resp boolean localTransaction = false; try { localTransaction = HibernateUtil.startLocalTransactionIfNeeded(); - - //http://jira.dotmarketing.net/browse/DOTCMS-2178 if(Field.FieldType.BINARY.toString().equals(field.getFieldType())){ List contentlets = conFac.findByStructure(structure.getInode(),0,0); @@ -854,9 +840,7 @@ public void run() { }); return; // Binary fields have nothing to do with database. - } - //https://github.com/dotCMS/core/issues/9909 - else if(Field.FieldType.TAG.toString().equals(field.getFieldType())){ + } else if(Field.FieldType.TAG.toString().equals(field.getFieldType())){ List contentlets = conFac.findByStructure(structure.getInode(),0,0); for(Contentlet contentlet : contentlets) { @@ -935,8 +919,6 @@ private IHTMLPage loadPageByIdentifier ( String ident, boolean live, Long langua /** * @deprecated As of 2016-05-16, replaced by {@link #loadPageByIdentifier(String, boolean, Long, User, boolean)} */ - - @Deprecated private IHTMLPage loadPageByIdentifier ( String ident, boolean live, User user, boolean frontRoles ) throws DotDataException, DotContentletStateException, DotSecurityException { return loadPageByIdentifier(ident, live, 0L, user, frontRoles); } @@ -966,6 +948,7 @@ public List> getContentletReferences(Contentlet contentlet, } return results; } + @Override public Object getFieldValue(Contentlet contentlet, com.dotcms.contenttype.model.field.Field theField){ if(theField instanceof ConstantField){ @@ -1005,6 +988,7 @@ public Object getFieldValue(Contentlet contentlet, com.dotcms.contenttype.model. return contentlet.get(theField.variable()); } } + @Override public Object getFieldValue(Contentlet contentlet, Field theField){ try { @@ -1134,9 +1118,6 @@ public ContentletRelationships getAllRelationships(Contentlet contentlet)throws records.setRecords(contentletList); matches.add(records); } - - - } return cRelationships; @@ -1672,10 +1653,9 @@ public void deleteAllVersionsandBackup(List contentlets, User user, contentletsVersion.addAll(findAllVersions(APILocator.getIdentifierAPI().find(con.getIdentifier()), user, respectFrontendRoles)); } - // jira.dotmarketing.net/browse/DOTCMS-1073 List contentletInodes = new ArrayList(); - for (Iterator iter = contentletsVersion.iterator(); iter.hasNext();) { - Contentlet element = (Contentlet) iter.next(); + for (Iterator iter = contentletsVersion.iterator(); iter.hasNext();) { + Contentlet element = iter.next(); contentletInodes.add(element.getInode()); } @@ -1707,7 +1687,6 @@ public void deleteAllVersionsandBackup(List contentlets, User user, } _xstream.toXML(contentlets, _bout); } - // jira.dotmarketing.net/browse/DOTCMS-1073 deleteBinaryFiles(contentletsVersion,null); } @@ -1740,10 +1719,9 @@ public void delete(List contentlets, User user, boolean respectFront } - // jira.dotmarketing.net/browse/DOTCMS-1073 List contentletInodes = new ArrayList(); - for (Iterator iter = contentletsVersion.iterator(); iter.hasNext();) { - Contentlet element = (Contentlet) iter.next(); + for (Iterator iter = contentletsVersion.iterator(); iter.hasNext();) { + Contentlet element = iter.next(); contentletInodes.add(element.getInode()); } @@ -1754,7 +1732,6 @@ public void delete(List contentlets, User user, boolean respectFront CacheLocator.getIdentifierCache().removeFromCacheByVersionable(contentlet); } - // jira.dotmarketing.net/browse/DOTCMS-1073 deleteBinaryFiles(contentletsVersion,null); } @@ -1786,7 +1763,6 @@ public void deleteVersion(Contentlet contentlet, User user,boolean respectFronte CacheLocator.getIdentifierCache().removeFromCacheByVersionable(contentlet); - // jira.dotmarketing.net/browse/DOTCMS-1073 deleteBinaryFiles(contentlets,null); } @@ -1967,6 +1943,12 @@ public void refresh(Structure structure) throws DotReindexStateException { } + /** + * + * @param contentlet + * @throws DotReindexStateException + * @throws DotDataException + */ private void refreshNoDeps(Contentlet contentlet) throws DotReindexStateException, DotDataException { indexAPI.addContentToIndex(contentlet, false); @@ -2598,6 +2580,21 @@ public Contentlet checkin(Contentlet contentlet, Map> contentRelationships, List cats, List permissions, User user, boolean respectFrontendRoles, boolean generateSystemEvent) @@ -3289,7 +3286,6 @@ else if (oldFile.exists()) { wapi.fireWorkflowPostCheckin(workflow); } - // DOTCMS-7290 DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); Host host = APILocator.getHostAPI().find(contIdent.getHostId(), user, respectFrontendRoles); ContentletServices.invalidateLive(contentlet); @@ -3306,7 +3302,7 @@ else if (oldFile.exists()) { CacheLocator.getVeloctyResourceCache().remove(velocityResourcePath); } - } catch (Exception e) {//DOTCMS-6946 + } catch (Exception e) { if(createNewVersion && workingContentlet!= null && UtilMethods.isSet(workingContentlet.getInode())){ APILocator.getVersionableAPI().setWorking(workingContentlet); } @@ -3585,7 +3581,7 @@ public String getName(Contentlet contentlet, User user, boolean respectFrontendR /** * This is the original method that copy the properties of one contentlet to another, this is tge original firm and call the overloaded firm with checkIsUnique false */ - + @Override public void copyProperties(Contentlet contentlet,Map properties) throws DotContentletStateException,DotSecurityException { boolean checkIsUnique = false; copyProperties(contentlet,properties, checkIsUnique); @@ -3600,7 +3596,6 @@ public void copyProperties(Contentlet contentlet,Map properties) * @throws DotContentletStateException * @throws DotSecurityException */ - public void copyProperties(Contentlet contentlet,Map properties,boolean checkIsUnique) throws DotContentletStateException,DotSecurityException { if(!InodeUtils.isSet(contentlet.getStructureInode())){ Logger.warn(this,"Cannot copy properties to contentlet where structure inode < 1 : You must set the structure's inode"); @@ -3661,7 +3656,7 @@ public void copyProperties(Contentlet contentlet,Map properties, contentlet.setFolder((String)value); }else if(velFieldmap.get(conVariable) != null){ Field field = velFieldmap.get(conVariable); - if(isFieldTypeString(field)) //|| field.getFieldType().equals(Field.FieldType.BINARY.toString())) + if(isFieldTypeString(field)) { if(checkIsUnique && field.isUnique()) { @@ -3700,12 +3695,6 @@ public void copyProperties(Contentlet contentlet,Map properties, contentlet.setStringProperty(Contentlet.WORKFLOW_EXPIRE_DATE, (String) properties.get(Contentlet.WORKFLOW_EXPIRE_DATE)); contentlet.setStringProperty(Contentlet.WORKFLOW_EXPIRE_TIME, (String) properties.get(Contentlet.WORKFLOW_EXPIRE_TIME)); contentlet.setStringProperty(Contentlet.WORKFLOW_NEVER_EXPIRE, (String) properties.get(Contentlet.WORKFLOW_NEVER_EXPIRE)); - - - - - - } } @@ -3740,15 +3729,15 @@ public List find(List categories,long languageId, boolean @Override public void setContentletProperty(Contentlet contentlet,Field field, Object value)throws DotContentletStateException { - String[] dateFormats = new String[] { "yyyy-MM-dd HH:mm", "d-MMM-yy", "MMM-yy", "MMMM-yy", "d-MMM", "dd-MMM-yyyy", "MM/dd/yyyy hh:mm aa", "MM/dd/yy HH:mm", + String[] dateFormats = new String[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "d-MMM-yy", "MMM-yy", "MMMM-yy", "d-MMM", "dd-MMM-yyyy", "MM/dd/yyyy hh:mm aa", "MM/dd/yy HH:mm", "MM/dd/yyyy HH:mm", "MMMM dd, yyyy", "M/d/y", "M/d", "EEEE, MMMM dd, yyyy", "MM/dd/yyyy", "hh:mm:ss aa", "HH:mm:ss", "yyyy-MM-dd"}; if(contentlet == null){ throw new DotContentletValidationException("The contentlet must not be null"); } - String stInode = contentlet.getStructureInode(); - if(!InodeUtils.isSet(stInode)){ - throw new DotContentletValidationException("The contentlet's structureInode must be set"); + String contentTypeInode = contentlet.getContentTypeId(); + if(!InodeUtils.isSet(contentTypeInode)){ + throw new DotContentletValidationException("The contentlet's Content Type Inode must be set"); } if(value==null || !UtilMethods.isSet(value.toString())) { @@ -3827,7 +3816,6 @@ public void setContentletProperty(Contentlet contentlet,Field field, Object valu throw new DotContentletStateException("Unable to set string value as a Long"); } } - // http://jira.dotmarketing.net/browse/DOTCMS-1073 // setBinary }else if(Field.FieldType.BINARY.toString().equals(field.getFieldType())){ try{ @@ -3838,7 +3826,6 @@ public void setContentletProperty(Contentlet contentlet,Field field, Object valu }catch (Exception e) { throw new DotContentletStateException("Unable to set binary file Object",e); } - //https://github.com/dotCMS/core/issues/10245 }else if(field.getFieldContentlet().startsWith("system_field")){ if(value.getClass()==java.lang.String.class){ try{ @@ -3852,10 +3839,14 @@ public void setContentletProperty(Contentlet contentlet,Field field, Object valu } } - private static final String[] SPECIAL_CHARS = new String[] { "+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^", "\"", "?", ":", "\\" }; + /** + * + * @param text + * @return + */ private static String escape(String text) { for (int i = SPECIAL_CHARS.length - 1; i >= 0; i--) { text = StringUtils.replace(text, SPECIAL_CHARS[i], "\\" + SPECIAL_CHARS[i]); @@ -3875,13 +3866,6 @@ public void validateContentlet(Contentlet contentlet,List cats)throws +" structureInode must be set"); } Structure st = CacheLocator.getContentTypeCache().getStructureByInode(contentlet.getStructureInode()); - - - - - - - if(Structure.STRUCTURE_TYPE_FILEASSET==st.getStructureType()){ if(contentlet.getHost()!=null && contentlet.getHost().equals(Host.SYSTEM_HOST) && (!UtilMethods.isSet(contentlet.getFolder()) || contentlet.getFolder().equals(FolderAPI.SYSTEM_FOLDER))){ DotContentletValidationException cve = new FileAssetValidationException("message.contentlet.fileasset.invalid.hostfolder"); @@ -3918,8 +3902,6 @@ public void validateContentlet(Contentlet contentlet,List cats)throws cve.addBadTypeField(st.getFieldVar(FileAssetAPI.HOST_FOLDER_FIELD)); throw cve; } - - } if(Structure.STRUCTURE_TYPE_HTMLPAGE == st.getStructureType()){ @@ -3973,17 +3955,6 @@ public void validateContentlet(Contentlet contentlet,List cats)throws throw cve; } } - - - - - - - - - - - boolean hasError = false; DotContentletValidationException cve = new DotContentletValidationException("Contentlets' fields are not valid"); List fields = FieldsCache.getFieldsByStructureInode(stInode); @@ -4019,7 +3990,6 @@ public void validateContentlet(Contentlet contentlet,List cats)throws cve.addBadTypeField(field); Logger.error(this,"A integer contentlet must be of type Long or Integer"); } - // http://jira.dotmarketing.net/browse/DOTCMS-1073 // binary field validation }else if(isFieldTypeBinary(field)){ if(!(o instanceof java.io.File)){ @@ -4171,7 +4141,7 @@ else if( field.getFieldType().equals(Field.FieldType.CATEGORY.toString()) ) { Map cMap = c.getMap(); Object obj = cMap.get(field.getVelocityVarName()); - if(((String) obj).equalsIgnoreCase(((String) o))) { //DOTCMS-7275 + if(((String) obj).equalsIgnoreCase(((String) o))) { unique = false; break; } @@ -4179,7 +4149,7 @@ else if( field.getFieldType().equals(Field.FieldType.CATEGORY.toString()) ) { } if(!unique) { - if(UtilMethods.isSet(contentlet.getIdentifier())){//DOTCMS-5409 + if(UtilMethods.isSet(contentlet.getIdentifier())){ Iterator contentletsIter = contentlets.iterator(); while (contentletsIter.hasNext()) { ContentletSearch cont = (ContentletSearch) contentletsIter.next(); @@ -4463,12 +4433,7 @@ public boolean isFieldTypeConstant(Field field) { return false; } - - - - /* (non-Javadoc) - * @see com.dotmarketing.portlets.contentlet.business.ContentletAPI#convertContentletToFatContentlet(com.dotmarketing.portlets.contentlet.model.Contentlet, com.dotmarketing.portlets.contentlet.business.Contentlet) - */ + @Override public com.dotmarketing.portlets.contentlet.business.Contentlet convertContentletToFatContentlet( Contentlet cont, com.dotmarketing.portlets.contentlet.business.Contentlet fatty) @@ -4476,9 +4441,7 @@ public com.dotmarketing.portlets.contentlet.business.Contentlet convertContentle return conFac.convertContentletToFatContentlet(cont, fatty); } - /* (non-Javadoc) - * @see com.dotmarketing.portlets.contentlet.business.ContentletAPI#convertFatContentletToContentlet(com.dotmarketing.portlets.contentlet.business.Contentlet) - */ + @Override public Contentlet convertFatContentletToContentlet( com.dotmarketing.portlets.contentlet.business.Contentlet fatty) throws DotDataException, DotSecurityException { @@ -4645,6 +4608,12 @@ private void moveBinaryFilesToTrash(List contentlets,Field field) { }); } + /** + * + * @param con + * @param field + * @return + */ private String getContentletAssetPath(Contentlet con, Field field) { String inode = con.getInode(); @@ -4662,6 +4631,13 @@ private String getContentletAssetPath(Contentlet con, Field field) { return result; } + + /** + * + * @param con + * @param field + * @return + */ private String getContentletCacheAssetPath(Contentlet con, Field field) { String inode = con.getInode(); @@ -4982,7 +4958,6 @@ public int compare(Contentlet o1, Contentlet o2) { APILocator.getVersionableAPI().setWorking(con); } - // https://github.com/dotCMS/dotCMS/issues/5620 // copy the workflow state WorkflowTask task = APILocator.getWorkflowAPI().findTaskByContentlet(contentletToCopy); if(task!=null) { @@ -5236,23 +5211,13 @@ public void removeUserReferences(String userId)throws DotDataException, DotSecur conFac.removeUserReferences(userId); } - /** - * Method will replace user references of the given userId in Contentlets - * with the replacement user id - * @param userToReplace the user to replace - * @param replacementUserId Replacement User Id - * @exception DotDataException There is a data error - * @throws DotSecurityException - */ + @Override public void updateUserReferences(User userToReplace, String replacementUserId, User user) throws DotDataException, DotSecurityException{ conFac.updateUserReferences(userToReplace, replacementUserId, user); } - @Override public String getUrlMapForContentlet(Contentlet contentlet, User user, boolean respectFrontendRoles) throws DotSecurityException, DotDataException { - - // no structure, no inode, no workee if (!InodeUtils.isSet(contentlet.getInode()) || !InodeUtils.isSet(contentlet.getStructureInode())) { return null; @@ -5268,18 +5233,12 @@ public String getUrlMapForContentlet(Contentlet contentlet, User user, boolean r return result; } - - - // if there is no detail page, return Structure structure = CacheLocator.getContentTypeCache().getStructureByInode(contentlet.getStructureInode()); if(!UtilMethods.isSet(structure.getDetailPage())) { return null; } - - - Identifier id = APILocator.getIdentifierAPI().find(contentlet.getIdentifier()); Host host = APILocator.getHostAPI().find(id.getHostId(), user, respectFrontendRoles); @@ -5324,17 +5283,10 @@ public String getUrlMapForContentlet(Contentlet contentlet, User user, boolean r } } - - - - if(result == null){ result = CONTENTLET_URL_MAP_FOR_CONTENT_404; } contentlet.setStringProperty(CONTENTLET_URL_MAP_FOR_CONTENT, result); - - - return result; } @@ -5632,6 +5584,7 @@ private void addURLToContentlet ( Contentlet contentlet, String url ) { } } + @Override public Contentlet checkin(Contentlet contentlet, ContentletRelationships contentRelationships, List cats, List selectedPermissions, User user, boolean respectFrontendRoles, boolean generateSystemEvent) throws IllegalArgumentException, @@ -5639,5 +5592,4 @@ public Contentlet checkin(Contentlet contentlet, ContentletRelationships content return checkin(contentlet, contentRelationships, cats, selectedPermissions, user, respectFrontendRoles, true, generateSystemEvent); } - }