Package com.dotmarketing.portlets.contentlet.model

Examples of com.dotmarketing.portlets.contentlet.model.Contentlet$ContentletHashMap


  }

  @SuppressWarnings("unchecked")
  public static Contentlet createContent(Structure st, ArrayList<Category> cats, String userId, List<String> parametersName,List<String[]> values, String options,List<Map<String,Object>> fileParameters, boolean autoPublish, Host formHost, String moderatorRole) throws DotContentletStateException, DotDataException, DotSecurityException{

    Contentlet contentlet = null;

    /*try {*/
    /**
     * Get the current user
     */
    User user = getUserFromId(userId);

    /**
     * Content inherit structure permissions
     */
    List<Permission> permissionList = perAPI.getPermissions(st);

    /**
     * Set the content values
     */
    contentlet = SubmitContentUtil.setAllFields(st.getName(), parametersName, values);


    /**
     * Get the required relationships
     */
    Map<Relationship,List<Contentlet>> relationships = SubmitContentUtil.getRelationships(st, contentlet, options,parametersName,values, user);


    /**
     * Validating content fields
     *
     */
    //conAPI.validateContentlet(contentlet,relationships,cats);

    /**
     * Set the binary field values
     * http://jira.dotmarketing.net/browse/DOTCMS-3463
     *
     */
    if(fileParameters.size() > 0){
      for(Map<String,Object> value : fileParameters){
        Field field = (Field)value.get("field");
        java.io.File file = (java.io.File)value.get("file");
        if(file!=null){
          try {
            contentlet.setBinary(field.getVelocityVarName(), file);
          } catch (IOException e) {

          }
        }
        else if(field.isRequired()) {
            DotContentletValidationException cve = new DotContentletValidationException("Contentlet's fields are not valid");
            cve.addRequiredField(field);
            throw cve;
        }
         }
    }

    if (st.getStructureType() == Structure.STRUCTURE_TYPE_FORM) {
      contentlet.setHost(formHost.getIdentifier());
      Host host = APILocator.getHostAPI().find(formHost.getIdentifier(), APILocator.getUserAPI().getSystemUser(), false);
      if (!perAPI.doesUserHavePermissions(host,"PARENT:"+PermissionAPI.PERMISSION_READ+", CONTENTLETS:"+PermissionAPI.PERMISSION_WRITE+"", user)) {
        throw new DotSecurityException("User doesn't have write permissions to Contentlet");
      }
    }

    /**
     * If the moderator field is set, a work flow task is created
     */
    if(UtilMethods.isSet(moderatorRole)){

      if(!UtilMethods.isSet(contentlet.getStringProperty(Contentlet.WORKFLOW_ACTION_KEY)))
        contentlet.setStringProperty(Contentlet.WORKFLOW_ACTION_KEY, APILocator.getWorkflowAPI().findEntryAction(contentlet, user).getId());

      String contentletTitle = "";

          List<Field> fields = FieldsCache.getFieldsByStructureInode(contentlet.getStructureInode());

          for (Field fld : fields) {
                  if(fld.isListed()){
                      contentletTitle = contentlet.getMap().get(fld.getVelocityVarName()).toString();
                      contentletTitle = contentletTitle.length() > 250 ? contentletTitle.substring(0,250) : contentletTitle;
                  }
          }
      contentlet.setStringProperty(Contentlet.WORKFLOW_COMMENTS_KEY, "A new content titled \"" + UtilHTML.escapeHTMLSpecialChars(contentletTitle.trim()) +
          "\" has been posted by " + UtilHTML.escapeHTMLSpecialChars(user.getFullName()) + " ("+user.getEmailAddress()+")");

      contentlet.setStringProperty(Contentlet.WORKFLOW_ASSIGN_KEY, roleAPI.loadRoleByKey(moderatorRole).getId());
    }
   
    /*
    * Saving file and images
    */
 
View Full Code Here


          redirectLink = "";
      }
       
        if(inode!=null){
         
          Contentlet contentlet = new Contentlet()
        try{
          contentlet = conAPI.checkout(inode, APILocator.getUserAPI().getSystemUser(), true);
        }catch(DotDataException e){
          Logger.error(this, "Unable to look up content with inode " + inode, e);
        }
     
        Structure contentletStructure = StructureCache.getStructureByInode(contentlet.getStructureInode());
        Identifier contentletIdentifier = APILocator.getIdentifierAPI().find(contentlet);
          Field field;
         
          /* Validate if a NumberOfClicks field exists in the contentlet structure
           if not, then create it and populate it.*/
         
        if (!InodeUtils.isSet(contentletStructure.getField("NumberOfClicks").getInode())) {
         
          List<Field> fields = new ArrayList<Field>();
            field = new Field("NumberOfClicks", Field.FieldType.TEXT, Field.DataType.TEXT, contentletStructure,
                        false, false, true, Integer.MAX_VALUE, "0", "0", "",true, true, true);
          FieldFactory.saveField(field);
          fields.add(field);
          FieldsCache.removeFields(contentletStructure);
          FieldsCache.addFields(contentletStructure,fields);
         
        }
        
        /* Get the  value from the NumberOfClicks field for this contentlet, if the value
         * is null, then the field does not exists, otherwise increment its value by one
         * and set it to the contentlet.
         */
        field = contentletStructure.getField("NumberOfClicks");
       
        String countValue = (contentlet.getStringProperty(field.getVelocityVarName()) ==  null) ? field.getDefaultValue() : (String)contentlet.getStringProperty(field.getVelocityVarName());
        int numberOfClicks  = new Integer(countValue).intValue();
        contentlet.setStringProperty(field.getVelocityVarName(),String.valueOf(numberOfClicks));
        conAPI.checkin(contentlet,new HashMap<Relationship, List<Contentlet>>(),new ArrayList<Category>(),new ArrayList<Permission>() ,APILocator.getUserAPI().getSystemUser(),true);
        }
        ActionForward af = new ActionForward(SecurityUtils.stripReferer(request, redirectLink));
          af.setRedirect(true);
          return af;
View Full Code Here

      while(APILocator.getFileAssetAPI().fileNameExists(host,folder, name, "")) {
        name = name + counter;
        counter++;
      }
     
      Contentlet cont = new Contentlet();
      cont.setStructureInode(folder.getDefaultFileType());
      cont.setStringProperty(FileAssetAPI.TITLE_FIELD, UtilMethods.getFileName(name));
      cont.setFolder(folder.getInode());
      cont.setHost(host.getIdentifier());
      cont.setBinary(FileAssetAPI.BINARY_FIELD, uploadedFile);
      APILocator.getContentletAPI().checkin(cont, user,false);
      APILocator.getVersionableAPI().setLive(cont);
      return APILocator.getFileAssetAPI().fromContentlet(cont);
 
View Full Code Here

   * @throws DotDataException
   */
  private static Contentlet setAllFields(String structureName, List<String> parametersName, List<String[]> values) throws DotDataException{

    Structure st = StructureCache.getStructureByName(structureName);
    Contentlet contentlet = new Contentlet();
    contentlet.setStructureInode(st.getInode());
    contentlet.setLanguageId(langAPI.getDefaultLanguage().getId());

    for(int i=0; i < parametersName.size(); i++){
      String fieldname = parametersName.get(i);
      String[] fieldValue = values.get(i);
      setField(st, contentlet, fieldname, fieldValue);
View Full Code Here

   * @throws DotSecurityException
   */
  @SuppressWarnings("unchecked")
  public static Contentlet createContent(Structure st, ArrayList<Category> cats, String userId, List<String> parametersName,List<String[]> values, String options,List<Map<String,Object>> fileParameters, boolean autoPublish) throws DotContentletStateException, DotDataException, DotSecurityException{

    Contentlet contentlet = null;

    /*try {*/
    /**
     * Get the current user
     */
 
View Full Code Here

    }
    return identifiers;
  }

  public List<Category> getContentletCategories(String inode) throws DotDataException, DotSecurityException {
    Contentlet content = conAPI.find(inode, user, true);
    return categoryAPI.getChildren(content, user, true);
  }
View Full Code Here

  public List<Relationship> getRelationshipsOfContentlet(long contentletInode) throws DotDataException, DotSecurityException {
    return getRelationshipsOfContentlet(((Long) contentletInode).toString());
  }

  public List<Relationship> getRelationshipsOfContentlet(String contentletInode) throws DotDataException, DotSecurityException {
    Contentlet cont = conAPI.find(contentletInode, user, true);
    return RelationshipFactory.getAllRelationshipsByStructure(cont.getStructure());
  }
View Full Code Here

  public List<Relationship> getRelationshipsOfContentlet(long contentletInode, boolean hasParent) throws DotDataException, DotSecurityException {
    return getRelationshipsOfContentlet(((Long) contentletInode).toString(), hasParent);
  }

  public List<Relationship> getRelationshipsOfContentlet(String contentletInode, boolean hasParent) throws DotDataException, DotSecurityException {
    Contentlet cont = conAPI.find(contentletInode, user, true);
    return RelationshipFactory.getAllRelationshipsByStructure(cont.getStructure(), hasParent);
  }
View Full Code Here

    return getRelatedContentlets(String.valueOf(relationshipInode), String.valueOf(contentletInode),hasParent);
  }

  public List<Contentlet> getRelatedContentlets(String relationshipInode, String contentletInode, boolean hasParent) throws DotDataException, DotSecurityException {
    Relationship relationship = (Relationship) InodeFactory.getInode(relationshipInode, Relationship.class);
    Contentlet contentlet = conAPI.find(contentletInode, user, true);
    return RelationshipFactory.getAllRelationshipRecords(relationship, contentlet, hasParent, true,"");
  }
View Full Code Here

    return RelationshipFactory.getAllRelationshipRecords(relationship, contentlet, hasParent, true,"");
  }

  public List<Contentlet> getRelatedChildContent(String relationshipName, String contentletInode) throws DotDataException, DotSecurityException {
    Relationship relationship = RelationshipFactory.getRelationshipByRelationTypeValue(relationshipName);
    Contentlet contentlet = conAPI.find(contentletInode, user, true);
    return RelationshipFactory.getAllRelationshipRecords(relationship, contentlet, true, true,"");
  }
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.contentlet.model.Contentlet$ContentletHashMap

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.