Package com.dotmarketing.portlets.contentlet.business

Examples of com.dotmarketing.portlets.contentlet.business.ContentletAPI


  public List<Map<String, Object>> findAllHostThumbnails() throws PortalException, SystemException, DotDataException, DotSecurityException {

    WebContext ctx = WebContextFactory.get();
    HttpServletRequest req = ctx.getHttpServletRequest();
    User user = userWebAPI.getLoggedInUser(req);
    ContentletAPI contentAPI = APILocator.getContentletAPI();

    boolean respectFrontend = !userWebAPI.isLoggedToBackend(req);
    List<Host> hosts = hostAPI.findAll(user, respectFrontend);
    Collections.sort(hosts, new HostNameComparator());

    List<Map<String, Object>> listOfHosts = new ArrayList<Map<String,Object>>(hosts.size());

    for(Host host : hosts) {
      if(host.isSystemHost())
        continue;
      Map<String, Object> thumbInfo = new HashMap<String, Object>();
      thumbInfo.put("hostId", host.getIdentifier());
      thumbInfo.put("hostInode", host.getInode());
      thumbInfo.put("hostName", host.getHostname());
      File hostThumbnail = contentAPI.getBinaryFile(host.getInode(), Host.HOST_THUMB_KEY, user);
      boolean hasThumbnail = hostThumbnail != null;
      thumbInfo.put("hasThumbnail", hasThumbnail);
      thumbInfo.put("tagStorage", host.getMap().get("tagStorage"));

      listOfHosts.add(thumbInfo);
View Full Code Here


    }

    //Rewriting the parent�s contentlets of the link
    List<Contentlet> contentlets = (List<Contentlet>)InodeFactory.getParentsOfClass(workingLink,
        Contentlet.class);
    ContentletAPI conAPI = APILocator.getContentletAPI();

    for( Contentlet cont : contentlets ) {
      if (cont.isWorking()) {
        com.dotmarketing.portlets.contentlet.model.Contentlet newFormatContentlet =
          conAPI.convertFatContentletToContentlet(cont);
        ContentletServices.invalidate(newFormatContentlet, true);
        //writes the contentlet object to a file
        ContentletMapServices.invalidate(newFormatContentlet, true);
      }
    }
View Full Code Here



  public String[] deleteContentletsFromIdList(String List, String userId) throws PortalException, SystemException, DotDataException,DotSecurityException {

    ContentletAPI conAPI = APILocator.getContentletAPI();
    String[] inodes = List.split(",");
    Integer contdeleted = 0;
    String contnotfound = "";
    String conthasreqrel = "";
    String conthasnoperm = "";

    User user = UserLocalManagerUtil.getUserById(userId);
    for (int i = 0; i < inodes.length; i++) {
      inodes[i] = inodes[i].trim();
    }

    List<Contentlet> contentlets = new ArrayList<Contentlet>();

    for (String inode : inodes) {
      if (!inode.trim().equals("")) {
        contentlets.addAll(conAPI.getSiblings(inode));
      }
    }

    for (Contentlet contentlet : contentlets) {
      conAPI.delete(contentlet, APILocator.getUserAPI().getSystemUser(), true, true);
      contdeleted++;
    }

    String[] results = { contdeleted.toString(), contnotfound, conthasreqrel,conthasnoperm };
View Full Code Here

    }
   
    if(perm == null) {
      //Content?
      ContentletAPI contAPI = APILocator.getContentletAPI();
     
      try {
        if(language == null || language <= 0){
          language=APILocator.getLanguageAPI().getDefaultLanguage().getId();
        }
        perm = contAPI.findContentletByIdentifier(assetId, false, language, user, respectFrontendRoles);
      } catch (DotContentletStateException e) {

      }
    }
View Full Code Here

      if (InodeFactory.isInode(inodeOrIdentifier)) {
        Inode inode = InodeFactory.find(inodeOrIdentifier);
        p = inode;
        asset.setType(((Permissionable) inode).getClass().getName());
      } else {
        ContentletAPI contAPI = APILocator.getContentletAPI();
        Contentlet content = contAPI.find(inodeOrIdentifier, user, false);

        if (UtilMethods.isSet(content) && content.getStructureInode().equals(hostStrucuture.getInode())) {
          p = content;
          asset.setType(Host.class.getName());
        }
View Full Code Here

            FieldFactory.deleteField(field);

        // delete related contentlets
        int limit = 200;
        int offset = 0;
        ContentletAPI conAPI=APILocator.getContentletAPI();
        List<Contentlet> contentlets=null;
        do {
            contentlets = conAPI.findByStructure(st, user, false, limit, offset);
            for(Contentlet contentlet : contentlets){
              contentlet.getMap().put(Contentlet.DONT_VALIDATE_ME, true);
            }
            conAPI.delete(contentlets, user, false);
        } while(contentlets.size()>0);

        //delete bad data contents
        deleteStructureContentlets(st.getInode());
       
        // delete Forms entry if it is a form structure
        if (st.getStructureType() == Structure.STRUCTURE_TYPE_FORM) {
            Structure sf = StructureCache.getStructureByVelocityVarName(
                    FormAPI.FORM_WIDGET_STRUCTURE_NAME_VELOCITY_VAR_NAME);
            if (UtilMethods.isSet(sf) && UtilMethods.isSet(sf.getInode())) {
                Field field = st.getFieldVar(FormAPI.FORM_WIDGET_FORM_ID_FIELD_VELOCITY_VAR_NAME);
                conAPI.delete( conAPI.search(
                        "+structureInode:" + sf.getInode() +
                        " +structureInode:" + st.getInode(), 0, 0,
                        "", user, false), user, false);
            }
        }
View Full Code Here

  }

  public void execute(JobExecutionContext ctx) throws JobExecutionException {
      try {
        ContentletAPI capi = APILocator.getContentletAPI();
        User pubUser = null;
        User expireUSer = null;
        try {
          pubUser = APILocator.getUserAPI().getSystemUser();
          expireUSer = APILocator.getUserAPI().getSystemUser();
        } catch (DotDataException e) {
          Logger.error(this.getClass(), e.getMessage(), e);
          throw new JobExecutionException(e);
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm00");
        String now = sdf.format(new Date());
   
        /*
         * do publish first, where publish is in the past and expire is in the
         * future and live = false
         */
        for (Structure s : getStructWithPublishField()) {
          StringWriter luceneQuery = new StringWriter();
          luceneQuery.append(" +structureName:" + s.getVelocityVarName());
          luceneQuery.append(" +" + s.getVelocityVarName() + "." + publishDateField + ":[19990101010000 to " + now + "]");
          luceneQuery.append(" +" + s.getVelocityVarName() + "." + expireDateField + ":[" + now + " to 20990101010000]");
          luceneQuery.append(" +live:false ");
          luceneQuery.append(" +working:true ");
          luceneQuery.append(" +deleted:false ");
   
          try {
            List<Contentlet> cons = capi.search(luceneQuery.toString(), 0, batchSize, null, expireUSer, false);
            while (cons.size() > 0) {
   
              capi.publish(cons, pubUser, false);
              Thread.sleep(500);
   
              cons = capi.search(luceneQuery.toString(), 0, batchSize, null, expireUSer, false);
            }
          } catch (Exception e) {
            Logger.error(this.getClass(), e.getMessage(), e);
            throw new JobExecutionException(e);
          }
        }
   
        /*
         * do expire second, where expire is in the past and live = true
         */
        for (Structure s : getStructWithExpireField()) {
          StringWriter luceneQuery = new StringWriter();
          luceneQuery.append(" +structureName:" + s.getVelocityVarName());
          luceneQuery.append(" +" + s.getVelocityVarName() + "." + expireDateField + ":[19990101010000 to " + now + "]");
          luceneQuery.append(" +live:true ");
          luceneQuery.append(" +working:true ");
          luceneQuery.append(" +deleted:false ");
   
          try {
            List<Contentlet> cons = capi.search(luceneQuery.toString(), 0, batchSize, null, expireUSer, false);
            while (cons.size() > 0) {
   
              capi.unpublish(cons, expireUSer, false);
              Thread.sleep(500);
             
              cons = capi.search(luceneQuery.toString(), 0, batchSize, null, expireUSer, false);
            }
          } catch (Exception e) {
            Logger.error(this.getClass(), e.getMessage(), e);
            throw new JobExecutionException(e);
          }
View Full Code Here

  /* (non-Javadoc)
   * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
   */
  @Override
  public void execute(JobExecutionContext jobContext) throws JobExecutionException {
    ContentletAPI contentletAPI = APILocator.getContentletAPI();
   
    JobDataMap map = jobContext.getJobDetail().getJobDataMap();
    Structure structure = (Structure) map.get("structure");
    User user = (User) map.get("user");
   
    try{
      //Lucene query to be sure that I will get all fields of the contentlet
      String luceneQuery = "+structureName:" + structure.getVelocityVarName() +
                " +working:true" +
                " +languageId:" + APILocator.getLanguageAPI().getDefaultLanguage().getId();
     
      //Identifiers will be updated 500 at a time
      Integer limit = 500;
      Integer offset = 0;
     
      //Get all the ContentletSearch
      List<ContentletSearch> contenletSearchList = contentletAPI.searchIndex(luceneQuery, limit, offset, "random", user, false);
     
      //If the query result is not empty
      while(!contenletSearchList.isEmpty()){
        //Start 500 (limit) transaction
        HibernateUtil.startTransaction();
       
        //Iterates all the ContentletSearch of the query
        for(ContentletSearch contentletSearch : contenletSearchList){
          //Get the identifier of each contentlet
          Identifier identifier= APILocator.getIdentifierAPI().find(contentletSearch.getIdentifier());
         
          //Gets from hibernate all the Data of the Contentlet
          com.dotmarketing.portlets.contentlet.business.Contentlet fatty =
              (com.dotmarketing.portlets.contentlet.business.Contentlet)HibernateUtil
              .load(com.dotmarketing.portlets.contentlet.business.Contentlet.class, contentletSearch.getInode());
         
          //Check if the new Publish Date Var is not null
          if(UtilMethods.isSet(structure.getPublishDateVar())){
            //Sets the identifier SysPublishDate to the new Structure/Content Publish Date Var
            identifier.setSysPublishDate((Date)fatty.getMap().get(structure.getPublishDateVar()));
          }else{
            identifier.setSysPublishDate(null);
          }
         
          //Check if the new Expire Date Var is not null
          if(UtilMethods.isSet(structure.getExpireDateVar())){
            //Sets the identifier SysExpireDate to the new Structure/Content Expire Date Var
            identifier.setSysExpireDate((Date)fatty.getMap().get(structure.getExpireDateVar()));
          }else{
            identifier.setSysExpireDate(null);
         
         
          //Saves the update
          APILocator.getIdentifierAPI().save(identifier);
          //Clears Identifier Cache
          CacheLocator.getIdentifierCache().removeFromCacheByIdentifier(contentletSearch.getIdentifier());
          //Clears Contentlet Cache for each language and version
          for(Language lan : APILocator.getLanguageAPI().getLanguages()) {
            ContentletVersionInfo versionInfo = APILocator.getVersionableAPI().getContentletVersionInfo(identifier.getId(), lan.getId()) ;
            if(versionInfo!=null && UtilMethods.isSet(versionInfo.getIdentifier())) {
              CacheLocator.getContentletCache().remove(versionInfo.getWorkingInode());
              if(UtilMethods.isSet(versionInfo.getLiveInode())) {
                CacheLocator.getContentletCache().remove(versionInfo.getLiveInode());
               
              }
            }
          }
        }
        //Commit 500 (limit) transaction
        HibernateUtil.commitTransaction();
       
        //Next 500
        limit += limit;
        offset += limit;
        contenletSearchList = contentletAPI.searchIndex(luceneQuery, limit, offset, "random", user, false);
      }
      //Send Notification
      String notificationMessage = LanguageUtil.get(user.getLocale(), "notifications_structure_identifiers_updated");
      Notification n = new Notification(notificationMessage, NotificationLevel.INFO, user.getUserId());
      APILocator.getNotificationAPI().saveNotification(n);
View Full Code Here

    // Asset Versions to list in the versions tab
    contentletFormData.put(WebKeys.VERSIONS_INODE_EDIT, contentlet);
  }

  private void _loadContentletRelationshipsInRequest(Map<String, Object> contentletFormData, Contentlet contentlet, Structure structure) throws DotDataException {
    ContentletAPI contentletService = APILocator.getContentletAPI();
    contentlet.setStructureInode(structure.getInode());
    ContentletRelationships cRelationships = contentletService.getAllRelationships(contentlet);
    contentletFormData.put(WebKeys.CONTENTLET_RELATIONSHIPS_EDIT, cRelationships);
  }
View Full Code Here

    String inodesSt;
    String[] inodes;
    Relationship relationship;
    String inode;
    Contentlet contentlet;
    ContentletAPI contentletAPI = APILocator.getContentletAPI();
    List<Contentlet> records = null;

    for (String key : keys) {
      if (key.startsWith("rel_") && key.endsWith("_inodes")) {
        hasParent = key.indexOf("_P_") != -1;
        inodesSt = (String) contentletFormData.get(key);
        inodes = inodesSt.split(",");
        relationship = (Relationship) InodeFactory.getInode(inodes[0], Relationship.class);
        contentletRelationshipRecords = new ContentletRelationships(null).new ContentletRelationshipRecords(relationship, hasParent);
        records = new ArrayList<Contentlet>();

        for (int i = 1; i < inodes.length; i++) {
          try {
            inode = inodes[i];
            contentlet = contentletAPI.find(inode, user, false);
            if ((contentlet != null) && (InodeUtils.isSet(contentlet.getInode())))
              records.add(contentlet);
          } catch (Exception e) {
            Logger.warn(this, e.toString());
          }
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.contentlet.business.ContentletAPI

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.