Package com.dotmarketing.portlets.structure.model

Examples of com.dotmarketing.portlets.structure.model.Structure


      loadPermissions(con, m);
      loadRelationshipFields(con, m);

      Identifier ident = APILocator.getIdentifierAPI().find(con);
      ContentletVersionInfo cvi = APILocator.getVersionableAPI().getContentletVersionInfo(ident.getId(), con.getLanguageId());
      Structure st=StructureCache.getStructureByInode(con.getStructureInode());

      Folder conFolder=APILocator.getFolderAPI().findFolderByPath(ident.getParentPath(), ident.getHostId(), APILocator.getUserAPI().getSystemUser(), false);

      m.put("title", con.getTitle());
      m.put("structureName", st.getVelocityVarName());
            m.put("structureType", st.getStructureType() + "");
            m.put("inode", con.getInode());
            m.put("type", "content");
            m.put("modDate", datetimeFormat.format(con.getModDate()));
            m.put("owner", con.getOwner()==null ? "0" : con.getOwner());
            m.put("modUser", con.getModUser());
View Full Code Here


  @SuppressWarnings("unchecked")
  protected void loadCategories(Contentlet con, Map<String,String> m) throws DotDataException, DotSecurityException {
      // first we check if there is a category field in the structure. We don't hit db if not needed
      boolean thereiscategory=false;
      Structure st=StructureCache.getStructureByInode(con.getStructureInode());
      List<Field> fields=FieldsCache.getFieldsByStructureInode(con.getStructureInode());
      for(Field f : fields)
          thereiscategory = thereiscategory ||
           f.getFieldType().equals(FieldType.CATEGORY.toString());

      String categoriesString="";

      if(thereiscategory) {
          String categoriesSQL = "select category.category_velocity_var_name as cat_velocity_var "+
                    " from  category join tree on (tree.parent = category.inode) join contentlet c on (c.inode = tree.child) " +
                    " where c.inode = ?";
          DotConnect db = new DotConnect();
            db.setSQL(categoriesSQL);
            db.addParam(con.getInode());
            ArrayList<String> categories=new ArrayList<String>();
          List<HashMap<String, String>> categoriesResults = db.loadResults();
          for (HashMap<String, String> crow : categoriesResults)
              categories.add(crow.get("cat_velocity_var"));

          categoriesString=UtilMethods.join(categories, " ").trim();

          for(Field f : fields) {
              if(f.getFieldType().equals(FieldType.CATEGORY.toString())) {
                  String catString="";
                  if(!categories.isEmpty()) {
                      String catId=f.getValues();

                      // we get all subcategories (recursive)
                      Category category=APILocator.getCategoryAPI().find(catId, APILocator.getUserAPI().getSystemUser(), false);
                      List<Category> childrens=APILocator.getCategoryAPI().getAllChildren(
                              category, APILocator.getUserAPI().getSystemUser(), false);

                      // we look for categories that match childrens for the
                      // categoryId of the field
                      ArrayList<String> fieldCategories=new ArrayList<String>();
                      for(String catvelvarname : categories)
                          for(Category chCat : childrens)
                              if(chCat.getCategoryVelocityVarName().equals(catvelvarname))
                                  fieldCategories.add(catvelvarname);

                      // after matching them we create the JSON field
                      if(!fieldCategories.isEmpty())
                          catString=UtilMethods.join(fieldCategories, " ").trim();
                  }
                  m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), catString);
              }
          }
      }

        m.put("categories", categoriesString);
View Full Code Here

    DecimalFormat numFormatter = new DecimalFormat("0000000000000000000.000000000000000000", otherSymbols);
   
      FieldAPI fAPI=APILocator.getFieldAPI();
      List<Field> fields = new ArrayList<Field>(FieldsCache.getFieldsByStructureInode(con.getStructureInode()));

      Structure st=con.getStructure();
        for (Field f : fields) {
            if (f.getFieldType().equals(Field.FieldType.BINARY.toString())
                    || f.getFieldContentlet() != null && f.getFieldContentlet().startsWith("system_field")) {
                continue;
            }
            if(!f.isIndexed()){
              continue;
            }
            try {
                if(fAPI.isElementConstant(f)){
                    m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), (f.getValues() == null ? "":f.getValues().toString()));
                    continue;
                }

                Object valueObj = con.get(f.getVelocityVarName());
                if(valueObj == null){
                    valueObj = "";
                }
                if (f.getFieldContentlet().startsWith("section_divider")) {
                    valueObj = "";
                }

                if(!UtilMethods.isSet(valueObj)) {
                    m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), "");
                }
                else if(f.getFieldType().equals("time")) {
                    String timeStr=timeFormat.format(valueObj);
                    m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), timeStr);
                }
                else if (f.getFieldType().equals("date")) {
                    try {
                        String dateString = dateFormat.format(valueObj);
                        m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), dateString);
                    }
                    catch(Exception ex) {
                        m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(),"");
                    }
                } else if(f.getFieldType().equals("date_time")) {
                    try {
                        String datetimeString = datetimeFormat.format(valueObj);
                        m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), datetimeString);
                    }
                    catch(Exception ex) {
                        m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(),"");
                    }
                } else if (f.getFieldType().equals("category")) {
                    // moved the logic to loadCategories
                } else if (f.getFieldType().equals("checkbox") || f.getFieldType().equals("multi_select")) {
                    if (f.getFieldContentlet().startsWith("bool")) {
                        m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), valueObj.toString());
                    } else {
                        m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), UtilMethods.listToString(valueObj.toString()));
                    }
                } else if (f.getFieldType().equals("key_value")){
                    boolean fileMetadata=f.getVelocityVarName().equals(FileAssetAPI.META_DATA_FIELD) && st.getStructureType()==Structure.STRUCTURE_TYPE_FILEASSET;
                  if(!fileMetadata || LicenseUtil.getLevel()>199) {

                      m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), (String)valueObj);
                        Map<String,Object> keyValueMap = KeyValueFieldUtil.JSONValueToHashMap((String)valueObj);

                        Set<String> allowedFields=null;
                        if(fileMetadata) {
                          // http://jira.dotmarketing.net/browse/DOTCMS-7243
                          List<FieldVariable> fieldVariables=APILocator.getFieldAPI().getFieldVariablesForField(
                                    f.getInode(), APILocator.getUserAPI().getSystemUser(), false);
                            for(FieldVariable fv : fieldVariables) {
                                if(fv.getKey().equals("dotIndexPattern")) {
                                    String[] names=fv.getValue().split(",");
                                    allowedFields=new HashSet<String>();
                                    for(String n : names)
                                        allowedFields.add(n.trim().toLowerCase());
                                }
                            }
                            // aditional fields from the configuration file
                            String configFields=Config.getStringProperty("INDEX_METADATA_FIELDS", "");
                            if(configFields.trim().length()>0) {
                                String[] names=configFields.split(",");
                                if(names.length>0 && allowedFields==null)
                                    allowedFields=new HashSet<String>();
                                for(String n : names)
                                    allowedFields.add(n.trim().toLowerCase());
                            }
                        }

                    if(keyValueMap!=null && !keyValueMap.isEmpty())
                      for(String key : keyValueMap.keySet())
                          if(allowedFields==null || allowedFields.contains(key.toLowerCase()))
                              m.put(st.getVelocityVarName() + "." + f.getVelocityVarName() + "." + key, (String)keyValueMap.get(key));
                  }
                } else if(f.getFieldType().equals(Field.FieldType.TAG.toString())) {
                    StringBuilder tagg=new StringBuilder();
                    for(Tag t : APILocator.getTagAPI().getTagsByInode(con.getInode()))
                        tagg.append(t.getTagName()).append(' ');
                    m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), tagg.toString());
                } else {
                    if (f.getFieldContentlet().startsWith("bool")) {
                        m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), valueObj.toString());
                    } else if (f.getFieldContentlet().startsWith("float") || f.getFieldContentlet().startsWith("integer")) {
                        m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), numFormatter.format(valueObj));
                    } else {
                        m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), valueObj.toString());
                    }
                }
            } catch (Exception e) {
                Logger.warn(ESMappingAPIImpl.class, "Error indexing field: " + f.getFieldName()
                        + " of contentlet: " + con.getInode(), e);
View Full Code Here

          }
          con.setHost(identifier.getHostId());
          con.setFolder(folder.getInode());

          // lets check if we have publish/expire fields to set
          Structure st=con.getStructure();
          if(UtilMethods.isSet(st.getPublishDateVar()))
              con.setDateProperty(st.getPublishDateVar(), identifier.getSysPublishDate());
          if(UtilMethods.isSet(st.getExpireDateVar()))
              con.setDateProperty(st.getExpireDateVar(), identifier.getSysExpireDate());
    }
       else{
           con.setHost(APILocator.getHostAPI().findSystemHost().getIdentifier());
           con.setFolder(APILocator.getFolderAPI().findSystemFolder().getInode());
       }
        String wysiwyg = fatty.getDisabledWysiwyg();
        if( UtilMethods.isSet(wysiwyg) ) {
            List<String> wysiwygFields = new ArrayList<String>();
            StringTokenizer st = new StringTokenizer(wysiwyg,",");
            while( st.hasMoreTokens() ) wysiwygFields.add(st.nextToken().trim());
            con.setDisabledWysiwyg(wysiwygFields);
        }
        return con;
  }
View Full Code Here

  @Override
  protected List<Contentlet> findContentletsWithFieldValue(String structureInode, Field field) throws DotDataException {
      List<Contentlet> result = new ArrayList<Contentlet>();

        try {
            Structure structure = StructureCache.getStructureByInode(structureInode);
            if ((structure == null) || (!InodeUtils.isSet(structure.getInode())))
                return result;

            if ((field == null) || (!InodeUtils.isSet(field.getInode())))
                return result;

            DotConnect dc = new DotConnect();
            String countSQL = ("select count(*) as count from contentlet, contentlet_version_info contentletvi" +
                               " where contentlet.identifier=contentletvi.identifier " +
                               " and contentletvi.live_inode=contentlet.inode " +
                               " and structure_inode= '" + structure.getInode() + "' and " +
                               field.getFieldContentlet() + " is not null and " +
                               field.getFieldContentlet() + "<>''");
            dc.setSQL(countSQL);
            List<HashMap<String, String>> resultCount = dc.getResults();
            int count = Integer.parseInt(resultCount.get(0).get("count"));
            int limit = 500;

            HibernateUtil hu = new HibernateUtil();
            hu.setQuery("from inode in class com.dotmarketing.portlets.contentlet.business.Contentlet, " +
                        " contentletvi in class "+ContentletVersionInfo.class.getName() +
                        " where contentletvi.identifier=inode.identifier " +
                        " and contentletvi.live_inode=inode.inode " +
                        " and structure_inode= '" + structure.getInode() + "' " +
                        " and " + field.getFieldContentlet() + " is not null" +
                        " and " + field.getFieldContentlet() + "<>'' " +
                        " order by " + field.getFieldContentlet());
            hu.setMaxResults(limit);
            for (int offset = 0; offset < count; offset+=limit) {
View Full Code Here

              return result;

          result = new TranslatedQuery();

          String originalQuery = query;
          Structure st = null;
          String stInodestr = "structureInode";
          String stInodeStrLowered = "structureinode";
          String stNameStrLowered = "structurename";

          if (query.contains(stNameStrLowered))
              query = query.replace(stNameStrLowered,"structureName");

          if (query.contains(stInodeStrLowered))
              query = query.replace(stInodeStrLowered,stInodestr);

          if (query.contains(stInodestr)) {
              // get structure information
              int index = query.indexOf(stInodestr) + stInodestr.length() + 1;
              String inode = null;
              try {
                  inode = query.substring(index, query.indexOf(" ", index));
              } catch (StringIndexOutOfBoundsException e) {
                  Logger.debug(ESContentFactoryImpl.class, e.toString());
                  inode = query.substring(index);
              }
              st = StructureCache.getStructureByInode(inode);
              if (!InodeUtils.isSet(st.getInode()) || !UtilMethods.isSet(st.getVelocityVarName())) {
                  Logger.error(ESContentFactoryImpl.class,
                          "Unable to find Structure or Structure Velocity Variable Name from passed in structureInode Query : "
                                  + query);

                  result.setQuery(query);
                  result.setSortBy(sortBy);

                  return result;
              }

              // replace structureInode
              query = query.replace("structureInode:"+inode, "structureName:" + st.getVelocityVarName());

              // handle the field translation
              List<com.dotmarketing.portlets.structure.model.Field> fields = FieldsCache.getFieldsByStructureVariableName(st.getVelocityVarName());
              Map<String, com.dotmarketing.portlets.structure.model.Field> fieldsMap;
              try {
                  fieldsMap = UtilMethods.convertListToHashMap(fields, "getFieldContentlet", String.class);
              } catch (Exception e) {
                  Logger.error(ESContentFactoryImpl.class, e.getMessage(), e);
                  result.setQuery(query);
                  result.setSortBy(sortBy);
                  return result;
              }
              String[] matcher = { "date", "text", "text_area", "integer", "float", "bool" };
              for (String match : matcher) {
                  if (query.contains(match)) {
                      List<RegExMatch> mathes = RegEX.find(query, match + "([1-9][1-5]?):");
                      for (RegExMatch regExMatch : mathes) {
                          String oldField = regExMatch.getMatch().substring(0, regExMatch.getMatch().indexOf(":"));
                          query = query.replace(oldField, st.getVelocityVarName() + "."
                                  + fieldsMap.get(oldField).getVelocityVarName());
                      }
                  }
              }
View Full Code Here

          if(sortBy == null)
              return null;

          List<RegExMatch> matches = RegEX.find(originalQuery,  "structureName:([^\\s)]+)");
          List<com.dotmarketing.portlets.structure.model.Field> fields = null;
          Structure structure = null;
          if(matches.size() > 0) {
              String structureName = matches.get(0).getGroups().get(0).getMatch();
              fields = FieldsCache.getFieldsByStructureVariableName(structureName);
              structure = StructureCache.getStructureByVelocityVarName(structureName);
          } else {
              matches = RegEX.find(originalQuery, "structureInode:([^\\s)]+)");
              if(matches.size() > 0) {
                  String structureInode = matches.get(0).getGroups().get(0).getMatch();
                  fields = FieldsCache.getFieldsByStructureInode(structureInode);
                  structure = StructureCache.getStructureByInode(structureInode);
              }
          }

          if(fields == null)
              return sortBy;

          Map<String, com.dotmarketing.portlets.structure.model.Field> fieldsMap;
          try {
              fieldsMap = UtilMethods.convertListToHashMap(fields, "getFieldContentlet", String.class);
          } catch (Exception e) {
              Logger.error(ESContentFactoryImpl.class, e.getMessage(), e);
              return sortBy;
          }

          String[] matcher = { "date", "text", "text_area", "integer", "float", "bool" };
          List<RegExMatch> mathes;
          String oldField, oldFieldTrim, newField;
          for (String match : matcher) {
              if (sortBy.contains(match)) {
                  mathes = RegEX.find(sortBy, match + "([1-9][1-5]?)");
                  for (RegExMatch regExMatch : mathes) {
                      oldField = regExMatch.getMatch();
                      oldFieldTrim = oldField.replaceAll("[,\\s]", "");
                      if(fieldsMap.get(oldFieldTrim) != null) {
                          newField = oldField.replace(oldFieldTrim, structure.getVelocityVarName() + "." + fieldsMap.get(oldFieldTrim).getVelocityVarName());
                          sortBy = sortBy.replace(oldField, newField);
                      }
                  }
              }
          }
View Full Code Here

            if (!UtilMethods.isSet(structureVarName)) {
                Logger.debug(ESContentFactoryImpl.class, "Structure Variable Name not found");
                //return query;
            }

            Structure selectedStructure = StructureCache.getStructureByVelocityVarName(structureVarName);

            if ((selectedStructure == null) || !InodeUtils.isSet(selectedStructure.getInode())) {
                Logger.debug(ESContentFactoryImpl.class, "Structure not found");
                //return query;
            }

            //delete additional blank spaces on date range
            if(UtilMethods.contains(query, "[ ")) {
                query = query.replace("[ ", "[");
            }

            if(UtilMethods.contains(query, " ]")) {
                query = query.replace(" ]", "]");
            }

            String clausesStr = RegEX.replaceAll(query, "", "[\\+\\-\\(\\)]*");
            String[] tokens = clausesStr.split(" ");
            String token;
            List<String> clauses = new ArrayList<String>();
            for (int pos = 0; pos < tokens.length; ++pos) {
                token = tokens[pos];
                if (token.matches("\\S+\\.\\S+:\\S*")) {
                    clauses.add(token);
                } else if (token.matches("\\d+:\\S*")) {
                    clauses.set(clauses.size() - 1, clauses.get(clauses.size() - 1) + " " + token);
                } else if (token.matches("\\[\\S*")) {
                    clauses.set(clauses.size() - 1, clauses.get(clauses.size() - 1) + token);
                } else if (token.matches("to")) {
                    clauses.set(clauses.size() - 1, clauses.get(clauses.size() - 1) + " " + token);
                } else if (token.matches("\\S*\\]")) {
                    clauses.set(clauses.size() - 1, clauses.get(clauses.size() - 1) + " " + token);
                } else if (token.matches("\\d{1,2}/\\d{1,2}/\\d{4}")) {
                    clauses.set(clauses.size() - 1, clauses.get(clauses.size() - 1) + " " + token);
                } else {
                    clauses.add(token);
                }
            }

            //DOTCMS - 4127
            List<com.dotmarketing.portlets.structure.model.Field> dateFields = new ArrayList<com.dotmarketing.portlets.structure.model.Field>();
            String tempStructureVarName;
            Structure tempStructure;

            for (String clause: clauses) {

                // getting structure names from query
                if(clause.indexOf('.') >= 0 && (clause.indexOf('.') < clause.indexOf(':'))){

                    tempStructureVarName = clause.substring(0, clause.indexOf('.'));
                    tempStructure = StructureCache.getStructureByVelocityVarName(tempStructureVarName);

                    List<com.dotmarketing.portlets.structure.model.Field> tempStructureFields = FieldsCache.getFieldsByStructureVariableName(tempStructure.getVelocityVarName());

                    for (int pos = 0; pos < tempStructureFields.size();) {

                        if (tempStructureFields.get(pos).getFieldType().equals(com.dotmarketing.portlets.structure.model.Field.FieldType.DATE_TIME.toString()) ||
                                tempStructureFields.get(pos).getFieldType().equals(com.dotmarketing.portlets.structure.model.Field.FieldType.DATE.toString()) ||
View Full Code Here

        fields = (List<Field>) cache.get(getPrimaryGroup() + inode, getPrimaryGroup());
      }catch (DotCacheException e) {
      Logger.debug(FieldsCache.class, "Cache Entry not found", e);
    }
        if (fields == null) {
            Structure st = StructureCache.getStructureByInode(inode);
            fields = st.getFields();
            if(fields.size()>0)
                addFields(st, fields);
        }
        return fields;
  }
View Full Code Here

                  fields = (List<Field>) cache.get(getPrimaryGroup() + velocityVarName, getPrimaryGroup());
                }catch (DotCacheException e) {
              Logger.debug(FieldsCache.class,"Cache Entry not found", e);
                }
            if(fields ==null){
                Structure st = StructureCache.getStructureByVelocityVarName(velocityVarName);
                fields = FieldFactory.getFieldsByStructure(st.getInode());
                if(fields.size()>0)
                    addFields(st, fields);
            }
          }
        }
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.structure.model.Structure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.