Package com.dotmarketing.portlets.contentlet.business

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


    }
  }

  private static void buildDefaultData() throws DotDataException {
    try {
      HostAPI hostAPI = APILocator.getHostAPI();
      PublicCompanyFactory.createDefaultCompany();
      // Ensures that default groups are set up
  //    GroupFactory.createDefaultGroups();
  //    try {
  //      LayoutFactory.createDefaultLayouts();
  //    } catch (Exception e) {
  //      throw new DotDataException(e.getMessage(), e);
  //    }
      // Creating the default host
      User systemUser = APILocator.getUserAPI().getSystemUser();
      List<Host> hosts = hostAPI.findAll(systemUser, false);
      if (hosts.size() == 0) {
        Logger.debug(DotCMSInitDb.class, "Creating Default Host");
        hostAPI.findDefaultHost(systemUser, false);
      }
          //Create Default Language
          APILocator.getLanguageAPI().createDefaultLanguage();
      // Creating the default content structures if it not exists.
      StructureFactory.createDefaultStructure();
View Full Code Here


        if(folder==null) folderInode=null;
        else folderInode = folder.getInode();
      }
      if(auxFolder != null)
      {
        HostAPI hostAPI = APILocator.getHostAPI();
        Host host;
        try {
          host = (Host) hostAPI.findParentHost(auxFolder, APILocator.getUserAPI().getSystemUser(), false);
        } catch (DotDataException e) {
          Logger.error(RefreshMenus.class, e.getMessage(), e);
          throw new DotRuntimeException(e.getMessage(), e);
        } catch (DotSecurityException e) {
          Logger.error(RefreshMenus.class, e.getMessage(), e);
View Full Code Here

    APILocator.getVersionableAPI().setDeleted(currWebAsset, false);
  }

  public static boolean unPublishAsset(WebAsset currWebAsset, String userId, Inode parent) throws DotStateException, DotDataException, DotSecurityException {
    ContentletAPI conAPI = APILocator.getContentletAPI();
    HostAPI hostAPI = APILocator.getHostAPI();
   
    // gets the identifier for this asset
    Identifier identifier = APILocator.getIdentifierAPI().find(currWebAsset);

    WebAsset workingwebasset = null;

    // gets the current working asset
    workingwebasset = (WebAsset) APILocator.getVersionableAPI().findWorkingVersion(identifier, APILocator.getUserAPI().getSystemUser(), false);

    WebAsset livewebasset = null;
   
    User modUser = null;
    try{
      modUser = APILocator.getUserAPI().loadUserById(workingwebasset.getModUser(),APILocator.getUserAPI().getSystemUser(),false);
    }catch(Exception ex){
      if(ex instanceof NoSuchUserException){
        try {
          modUser = APILocator.getUserAPI().getSystemUser();
        } catch (DotDataException e) {
          Logger.error(WebAssetFactory.class,e.getMessage(),e);
        }
      }
    }
    if(modUser!=null){
       workingwebasset.setModUser(modUser.getUserId());
    }

    if (!workingwebasset.isLocked() || workingwebasset.getModUser().equals(userId)) {
      try {
        // gets the current working asset
        livewebasset = (WebAsset) APILocator.getVersionableAPI().findLiveVersion(identifier, APILocator.getUserAPI().getSystemUser(), false);
       
            APILocator.getVersionableAPI().removeLive(identifier.getId());
        livewebasset.setModDate(new java.util.Date());
        livewebasset.setModUser(userId);
        HibernateUtil.saveOrUpdate(livewebasset);

        if ((livewebasset.getInode() != workingwebasset.getInode())) {
              APILocator.getVersionableAPI().setLocked(workingwebasset, false, null);       
          // removes from folder or parent inode
          if(parent != null)
            parent.deleteChild(workingwebasset);
        }

        if (currWebAsset instanceof HTMLPage) {
          //remove page from the live directory
          PageServices.unpublishPageFile((HTMLPage)currWebAsset);

          //Refreshing the menues
          //RefreshMenus.deleteMenus();
          RefreshMenus.deleteMenu(currWebAsset);
          CacheLocator.getNavToolCache().removeNavByPath(identifier.getHostId(), identifier.getParentPath());

        } else if (currWebAsset instanceof Container) {
          //remove container from the live directory
          ContainerServices.unpublishContainerFile((Container)currWebAsset);
        } else if (currWebAsset instanceof Template) {
          //remove template from the live directory
          TemplateServices.unpublishTemplateFile((Template)currWebAsset);
        } else if( currWebAsset instanceof Link ) {
          // Removes static menues to provoke all possible dependencies be generated.
          if( parent instanceof Folder ) {
            Folder parentFolder = (Folder)parent;     
            Host host = hostAPI.findParentHost(parentFolder, APILocator.getUserAPI().getSystemUser(), false);
            RefreshMenus.deleteMenu(host);
            CacheLocator.getNavToolCache().removeNav(host.getIdentifier(), parentFolder.getInode());
          }
        } else if (currWebAsset instanceof File) {
            RefreshMenus.deleteMenu(currWebAsset);
View Full Code Here

     * @param languageId
     * @return
     */
    public static String addToLiveAssetToCache ( Versionable asset, Long languageId ) {

        HostAPI hostAPI = APILocator.getHostAPI();

      DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
        //The default value for velocity page extension
        String ext = Config.getStringProperty("VELOCITY_PAGE_EXTENSION");
    // we use the identifier uri for our mappings.
        String ret = null;
        try{
          Identifier id = APILocator.getIdentifierAPI().find(asset);
          //Obtain the host of the webassets
          User systemUser = APILocator.getUserAPI().getSystemUser();
        Host host = hostAPI.findParentHost((Treeable)asset, systemUser, false);
        if(host == null) ret = null;

        //Obtain the URI for future uses
        String uri = id.getURI();
        //Obtain the inode value of the host;
View Full Code Here

   * to the cluster when the cms is in cluster
   * @param asset
   */
  public static void removeAssetFromCache(Versionable asset){
    DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
      HostAPI hostAPI = APILocator.getHostAPI();

    try{
        User systemUser = APILocator.getUserAPI().getSystemUser();
        Host host = hostAPI.findParentHost((Treeable)asset, systemUser, false);
        if(host == null)
          return;
        String hostId = host.getIdentifier();
      Identifier identifier = APILocator.getIdentifierAPI().find(asset);

View Full Code Here

   */
  @SuppressWarnings("unchecked")
  public static boolean publishAsset(Inode webAsset, User user, boolean respectFrontendRoles, boolean isNewVersion) throws WebAssetException, DotSecurityException, DotDataException
  {
    ContentletAPI conAPI = APILocator.getContentletAPI();
    HostAPI hostAPI = APILocator.getHostAPI();
   
    //http://jira.dotmarketing.net/browse/DOTCMS-6325
    if (user != null &&
        ((webAsset instanceof Folder)?
        !permissionAPI.doesUserHavePermission(webAsset, PermissionAPI.PERMISSION_EDIT, user):
        !permissionAPI.doesUserHavePermission(webAsset, PERMISSION_PUBLISH, user))) {
      Logger.debug(PublishFactory.class, "publishAsset: user = " + user.getEmailAddress() + ", don't have permissions to publish: " + webAsset);
      return false;
    }
   
    if (webAsset instanceof WebAsset)
    {
      try {
        WebAssetFactory.publishAsset((WebAsset) webAsset, user, isNewVersion);
      } catch (Exception e) {
        Logger.error(PublishFactory.class, "publishAsset: Failed to publish the asset.", e);
      }
    }

    if (webAsset instanceof com.dotmarketing.portlets.files.model.File)
    {
      // publishing a file
      LiveCache.removeAssetFromCache((WebAsset)webAsset);
      LiveCache.addToLiveAssetToCache((WebAsset) webAsset);
      WorkingCache.removeAssetFromCache((WebAsset)webAsset);
      WorkingCache.addToWorkingAssetToCache((WebAsset) webAsset);
      if(RefreshMenus.shouldRefreshMenus((com.dotmarketing.portlets.files.model.File)webAsset)){
        com.dotmarketing.menubuilders.RefreshMenus.deleteMenu((WebAsset)webAsset);
        Identifier ident=APILocator.getIdentifierAPI().find(webAsset);
        CacheLocator.getNavToolCache().removeNavByPath(ident.getHostId(), ident.getParentPath());
      }

    }

    if (webAsset instanceof Container) {

      //saves to live folder under velocity
      ContainerServices.invalidate((Container)webAsset);
    }


    if (webAsset instanceof Template) {

        Logger.debug(PublishFactory.class, "*****I'm a Template -- Publishing");

      //gets all identifier children
      java.util.List<Container> identifiers = APILocator.getTemplateAPI().getContainersInTemplate((Template)webAsset, APILocator.getUserAPI().getSystemUser(), false);
      java.util.Iterator<Container> identifiersIter = identifiers.iterator();
      while (identifiersIter.hasNext()) {

        Container container =(Container) identifiersIter.next();

          Logger.debug(PublishFactory.class, "*****I'm a Template -- Publishing my Container Child=" + container.getInode());
          if(!container.isLive()){
            publishAsset(container,user, respectFrontendRoles, isNewVersion);
          }
       
       
      }

            //Clean-up the cache for this template
            CacheLocator.getTemplateCache().remove( webAsset.getInode() );
            //writes the template to a live directory under velocity folder
      TemplateServices.invalidate((Template)webAsset);

    }

    if (webAsset instanceof HTMLPage)
    {

        Logger.debug(PublishFactory.class, "*****I'm an HTML Page -- Publishing");

        List relatedNotPublished = new ArrayList();
        relatedNotPublished = getUnpublishedRelatedAssets(webAsset, relatedNotPublished, user, respectFrontendRoles);
       
        //Publishing related pieces of content
        for(Object asset : relatedNotPublished) {
          if(asset instanceof Contentlet) {
          Logger.debug(PublishFactory.class, "*****I'm an HTML Page -- Publishing my Contentlet Child=" + ((Contentlet)asset).getInode());
          try {
            Contentlet c = (Contentlet)asset;
            if(!APILocator.getWorkflowAPI().findSchemeForStruct(c.getStructure()).isMandatory()){
              conAPI.publish((Contentlet)asset, user, false);
            }
          } catch (DotSecurityException e) {
            //User has no permission to publish the content in the page so we just skip it
            Logger.debug(PublishFactory.class, "publish html page: User has no permission to publish the content inode = " + ((Contentlet)asset).getInode() + " in the page, skipping it.");
          }           
          }else if(asset instanceof Template){
            Logger.debug(PublishFactory.class, "*****I'm an HTML Page -- Publishing Template =" + ((Template)asset).getInode());
            publishAsset((Template)asset,user, respectFrontendRoles,false);
          }
        }

        LiveCache.removeAssetFromCache((WebAsset) webAsset);
      LiveCache.addToLiveAssetToCache((WebAsset) webAsset);
      WorkingCache.removeAssetFromCache((WebAsset) webAsset);
      WorkingCache.addToWorkingAssetToCache((WebAsset) webAsset);
      //writes the htmlpage to a live directory under velocity folder
      PageServices.invalidate((HTMLPage)webAsset);

            //Refreshing the menues
     
     
      if(RefreshMenus.shouldRefreshMenus((HTMLPage)webAsset)){
        Folder folder = (Folder) APILocator.getFolderAPI().findParentFolder((Treeable)webAsset,user,false);
        if(folder != null){
          RefreshMenus.deleteMenu(folder);
          CacheLocator.getNavToolCache().removeNav(folder.getHostId(),folder.getInode());
        }
      }
            CacheLocator.getHTMLPageCache().remove((HTMLPage) webAsset);

    }

    if (webAsset instanceof Folder) {

      Folder parentFolder = (Folder) webAsset;

        Logger.debug(PublishFactory.class, "*****I'm a Folder -- Publishing" + parentFolder.getName());

      //gets all links for this folder
      java.util.List foldersListSubChildren = APILocator.getFolderAPI().findSubFolders(parentFolder,APILocator.getUserAPI().getSystemUser(),false);
      //gets all links for this folder
      java.util.List linksListSubChildren = APILocator.getFolderAPI().getWorkingLinks(parentFolder, user, false);
      //gets all html pages for this folder
      java.util.List htmlPagesSubListChildren = APILocator.getFolderAPI().getWorkingHTMLPages(parentFolder,user,false);
      //gets all files for this folder
      java.util.List filesListSubChildren = APILocator.getFolderAPI().getWorkingFiles(parentFolder,user,false);
      //gets all templates for this folder
      //java.util.List templatesListSubChildren = APILocator.getFolderAPI().getWorkingChildren(parentFolder,Template.class);
      //gets all containers for this folder
      //java.util.List containersListSubChildren = APILocator.getFolderAPI().getWorkingChildren(parentFolder,Container.class);

      //gets all subitems
      java.util.List elements = new java.util.ArrayList();
      elements.addAll(foldersListSubChildren);
      elements.addAll(linksListSubChildren);
      elements.addAll(htmlPagesSubListChildren);
      elements.addAll(filesListSubChildren);
      //elements.addAll(templatesListSubChildren);
      //elements.addAll(containersListSubChildren);

      java.util.Iterator elementsIter = elements.iterator();
      while (elementsIter.hasNext()) {
        Inode inode = (Inode) elementsIter.next();
          Logger.debug(PublishFactory.class, "*****I'm a Folder -- Publishing my Inode Child=" + inode.getInode());
        publishAsset(inode,user, respectFrontendRoles, isNewVersion);
      }
     
      java.util.List<Contentlet> contentlets = conAPI.findContentletsByFolder(parentFolder, user, false);
      java.util.Iterator<Contentlet> contentletsIter = contentlets.iterator();
      while (contentletsIter.hasNext()) {
        //publishes each one
        Contentlet contentlet = (Contentlet)contentletsIter.next();
        Logger.debug(PublishFactory.class, "*****I'm a Folder -- Publishing my Inode Child=" + contentlet.getInode());
        if(!contentlet.isLive() && !contentlet.isArchived() && (permissionAPI.doesUserHavePermission(contentlet, PERMISSION_PUBLISH, user, respectFrontendRoles))) {
          APILocator.getContentletAPI().publish(contentlet, user, false);
        }
      }
    }

    if (webAsset instanceof Link) {
      List contentlets = InodeFactory.getParentsOfClass(webAsset, com.dotmarketing.portlets.contentlet.business.Contentlet.class);
      Iterator it = contentlets.iterator();
      while (it.hasNext()) {
        com.dotmarketing.portlets.contentlet.business.Contentlet cont = (com.dotmarketing.portlets.contentlet.business.Contentlet) it.next();
          if (cont.isLive()) {
            try {
              com.dotmarketing.portlets.contentlet.model.Contentlet newFormatContentlet =
              conAPI.convertFatContentletToContentlet(cont);
            ContentletServices.invalidate(newFormatContentlet,  false);
              ContentletMapServices.invalidate(newFormatContentlet, false);
          } catch (DotDataException e) {
            throw new WebAssetException(e.getMessage(), e);
          }
          }
      }
      // Removes static menues to provoke all possible dependencies be generated.
      Folder parentFolder = (Folder)APILocator.getFolderAPI().findParentFolder((Treeable) webAsset,user,false);
      Host host = (Host) hostAPI.findParentHost(parentFolder, APILocator.getUserAPI().getSystemUser(), respectFrontendRoles);
      RefreshMenus.deleteMenu(host);
      CacheLocator.getNavToolCache().removeNav(host.getIdentifier(), parentFolder.getInode());
    }   
   
    return true;
View Full Code Here

              }
          }

        Structure hostStructure = StructureCache.getStructureByVelocityVarName("Host");
        if ((contentlet != null) && InodeUtils.isSet(contentlet.getIdentifier()) && contentlet.getStructureInode().equals(hostStructure.getInode())) {
            HostAPI hostAPI = APILocator.getHostAPI();
            hostAPI.updateCache(new Host(contentlet));

            ContentletCache cc = CacheLocator.getContentletCache();
            Identifier ident=APILocator.getIdentifierAPI().find(contentlet);
            List<Contentlet> contentlets = findAllVersions(ident, sysuser, respectFrontendRoles);
            for (Contentlet c : contentlets) {
            Host h = new Host(c);
            cc.remove(h.getHostname());
            cc.remove(h.getIdentifier());
          }

            hostAPI.updateVirtualLinks(new Host(workingContentlet), new Host(contentlet));//DOTCMS-5025
            hostAPI.updateMenuLinks(new Host(workingContentlet), new Host(contentlet));

          //update tag references
            String oldTagStorageId = "SYSTEM_HOST";
            if(workingContentlet.getMap().get("tagStorage")!=null) {
              oldTagStorageId = workingContentlet.getMap().get("tagStorage").toString();
View Full Code Here

      return resultContentlet;
    }

    public Contentlet copyContentlet(Contentlet contentlet, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException, DotContentletStateException {
        HostAPI hostAPI = APILocator.getHostAPI();
        FolderAPI folderAPI = APILocator.getFolderAPI();

        String hostIdentfier = contentlet.getHost();
        Identifier contIdentifier = APILocator.getIdentifierAPI().find(contentlet);

        Host host = hostAPI.find(hostIdentfier, user, respectFrontendRoles);
        if(host == null)
            host = new Host();
        Folder folder = folderAPI.findFolderByPath(contIdentifier.getParentPath(), host, user, false);

        return copyContentlet(contentlet, host, folder, user, needAppendCopy(contentlet,host,folder), respectFrontendRoles);
View Full Code Here

    private static Language defaultLanguage;

    @BeforeClass
    public static void prepare () throws DotSecurityException, DotDataException {

        HostAPI hostAPI = APILocator.getHostAPI();
        LanguageAPI languageAPI = APILocator.getLanguageAPI();

        //Setting the test user
        user = APILocator.getUserAPI().getSystemUser();
        defaultHost = hostAPI.findDefaultHost( user, false );
        pageExt = Config.getStringProperty( "VELOCITY_PAGE_EXTENSION" );
        //Getting the default language
        defaultLanguage = languageAPI.getDefaultLanguage();

        /*
 
View Full Code Here

    }

    public void permissionIndividually(Permissionable parent, Permissionable permissionable, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException{
      List<Permission> perList = new ArrayList<Permission>();
      List<Permission> newSetOfPermissions = new ArrayList<Permission>();
      HostAPI hostAPI = APILocator.getHostAPI();
    User systemUser = APILocator.getUserAPI().getSystemUser();

    if(!doesUserHavePermission(permissionable, PermissionAPI.PERMISSION_EDIT_PERMISSIONS, user))
      throw new DotSecurityException("User id: " + user.getUserId() + " does not have permission to alter permissions on asset " + permissionable.getPermissionId());

      if(parent.isParentPermissionable()){

        String type = permissionable.getPermissionType();
        perList.addAll(permissionFactory.getInheritablePermissions(parent));
        perList.addAll(permissionFactory.getPermissions(parent,true));
        Host host = hostAPI.find(permissionable.getPermissionId(), systemUser, false);
      if(host != null) {
        type = Host.class.getCanonicalName();
      }
        for(Permission p : perList){
View Full Code Here

TOP

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

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.