Package com.dotmarketing.beans

Examples of com.dotmarketing.beans.Identifier


    if (host != null && InodeUtils.isSet(host.getInode()) && InodeUtils.isSet(folder.getInode())) {
      IFileAsset destinationFile = null;
      java.io.File workingFile = null;
      Folder parent = null;
      Contentlet fileAssetCont = null;
      Identifier identifier  = APILocator.getIdentifierAPI().find(host, path);
      if(identifier!=null && InodeUtils.isSet(identifier.getId()) && identifier.getAssetType().equals("contentlet")){
        fileAssetCont = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
        workingFile = fileAssetCont.getBinary(FileAssetAPI.BINARY_FIELD);
        destinationFile = APILocator.getFileAssetAPI().fromContentlet(fileAssetCont);
        parent = APILocator.getFolderAPI().findFolderByPath(identifier.getParentPath(), host, user, false);

        if(fileAssetCont.isArchived()) {
            APILocator.getContentletAPI().unarchive(fileAssetCont, user, false);
        }
      }else if(identifier!=null && InodeUtils.isSet(identifier.getId())){
        destinationFile = fileAPI.getFileByURI(path, host, false, user, false);
        // inode{1}/inode{2}/inode.file_extension
        workingFile = fileAPI.getAssetIOFile((File)destinationFile);

        if(destinationFile.isArchived()) {
View Full Code Here


      if (toParentFolder == null || !InodeUtils.isSet(toParentFolder.getInode())) {
        throw new IOException("Cannot move a file to the root of the host.");
      }

      try{
        Identifier identifier  = APILocator.getIdentifierAPI().find(host, getPath(fromPath));

        Identifier identTo  = APILocator.getIdentifierAPI().find(host, getPath(toPath));
        boolean destinationExists=identTo!=null && InodeUtils.isSet(identTo.getId());

        if(identifier!=null && identifier.getAssetType().equals("contentlet")){
          Contentlet fileAssetCont = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
          if(!destinationExists) {
              if (getFolderName(fromPath).equals(getFolderName(toPath))) {
                String fileName = getFileName(toPath);
                if(fileName.contains(".")){
                  fileName = fileName.substring(0, fileName.lastIndexOf("."));
                }
                APILocator.getFileAssetAPI().renameFile(fileAssetCont, fileName, user, false);
              } else {
                APILocator.getFileAssetAPI().moveFile(fileAssetCont, toParentFolder, user, false);
              }
          }
          else {
              // if the destination exists lets just create a new version and delete the original file
              Contentlet origin = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
              Contentlet toContentlet = APILocator.getContentletAPI().findContentletByIdentifier(identTo.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
              Contentlet newversion = APILocator.getContentletAPI().checkout(toContentlet.getInode(), user, false);

              // get a copy in a tmp folder to avoid filename change
              java.io.File tmpDir=new java.io.File(APILocator.getFileAPI().getRealAssetPathTmpBinary()
                                +java.io.File.separator+UUIDGenerator.generateUuid());
View Full Code Here

      Logger.error(DotWebdavHelper.class, e.getMessage(), e);
      throw new IOException(e.getMessage());
    }
    Folder folder = folderAPI.findFolderByPath(folderName, host,user,false);
    if (isResource(uri,user)) {
      Identifier identifier  = APILocator.getIdentifierAPI().find(host, path);

      Long timeOfPublishing = fileResourceCache.get(uri + "|" + user.getUserId());
      Date currentDate = new Date();
      long diff = -1;
      long minTimeAllowed = Config.getIntProperty("WEBDAV_MIN_TIME_AFTER_PUBLISH_TO_ALLOW_DELETING_OF_FILES", 10);
      boolean canDelete= true;

      if(UtilMethods.isSet(timeOfPublishing)) {
        diff = (currentDate.getTime()-timeOfPublishing)/1000;
        canDelete = diff >= minTimeAllowed;
      }

      if(identifier!=null && identifier.getAssetType().equals("contentlet")){
          Contentlet fileAssetCont = APILocator.getContentletAPI()
              .findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
         
          //Webdav calls the delete method when is creating a new file. But it creates the file with 0 content length.
          //No need to wait 10 seconds with files with 0 length.
          if(canDelete
              || (fileAssetCont.getBinary(FileAssetAPI.BINARY_FIELD) != null
                && fileAssetCont.getBinary(FileAssetAPI.BINARY_FIELD).length() <= 0)){
           
            try{
                APILocator.getContentletAPI().archive(fileAssetCont, user, false);
            }catch (Exception e) {
                Logger.error(DotWebdavHelper.class, e.getMessage(), e);
                throw new DotDataException(e.getMessage(), e);
            }
           
            WorkingCache.removeAssetFromCache(fileAssetCont);
            LiveCache.removeAssetFromCache(fileAssetCont);
            fileResourceCache.remove(uri + "|" + user.getUserId());
          }
      } else {
          webAsset = fileAPI.getFileByURI(path, host, false, user, false);
          // This line just archive the assets
          // WebAssetFactory.deleteAsset(file, user.getUserId());
          // This line delete the assets (no archive)
          try{
              WebAssetFactory.archiveAsset(webAsset, user);
          }catch (Exception e) {
              Logger.error(DotWebdavHelper.class, e.getMessage(), e);
              throw new DotDataException(e.getMessage(), e);
          }
          WorkingCache.removeAssetFromCache(webAsset);
          LiveCache.removeAssetFromCache(webAsset);
      }

    } else if (isFolder(uri,user)) {
      if(!path.endsWith("/"))
        path += "/";
      folder = folderAPI.findFolderByPath(path, host,user,false);
      if (folder.isShowOnMenu()) {
        // RefreshMenus.deleteMenus();
        RefreshMenus.deleteMenu(folder);
        CacheLocator.getNavToolCache().removeNav(folder.getHostId(), folder.getInode());
        if(!path.equals("/")) {
            Identifier ii=APILocator.getIdentifierAPI().find(folder);
            CacheLocator.getNavToolCache().removeNavByPath(ii.getHostId(), ii.getParentPath());
        }
      }

      folderAPI.delete(folder, user,false);
View Full Code Here

                String fileUri = "";
                java.io.File workingFile = null;
                FileInputStream is = null;
                Date idate = null;
                if(file instanceof Contentlet){
                  Identifier identifier  = APILocator.getIdentifierAPI().find((Contentlet) file);
                  if(identifier!=null && identifier.getAssetType().equals("contentlet")){
                    fileUri = identifier.getPath();
                    workingFile = ((Contentlet)file).getBinary(FileAssetAPI.BINARY_FIELD);
                    is = new FileInputStream(workingFile);
                    idate = ((Contentlet)file).getModDate();
                  }
                }else if(file instanceof File){
View Full Code Here

      Logger.error(DotWebdavHelper.class, e.getMessage(), e);
      throw new IOException(e.getMessage());
    }
    if (host != null && InodeUtils.isSet(host.getInode()) && InodeUtils.isSet(folder.getInode())) {
      java.io.File workingFile  = null;
      Identifier identifier  = APILocator.getIdentifierAPI().find(host, path);
      if(identifier!=null && identifier.getAssetType().equals("contentlet")){
                Contentlet cont  = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
          workingFile = cont.getBinary(FileAssetAPI.BINARY_FIELD);
      }else{
        File file = fileAPI.getFileByURI(path, host, false, user, false);
        // inode{1}/inode{2}/inode.file_extension
        workingFile = fileAPI.getAssetIOFile(file);
View Full Code Here

  public List<Identifier> findByURIPattern(String assetType, String uri, boolean hasLive,boolean onlyDeleted, boolean include, Host host, Date startDate, Date endDate) throws DotDataException {
    return ifac.findByURIPattern(assetType, uri, hasLive,onlyDeleted,include, host, startDate, endDate);
  }
 
  public Identifier findFromInode(String inodeOrIdentifier) throws DotDataException {
    Identifier ident = ifac.loadFromCache(inodeOrIdentifier);

    if(ident == null || !InodeUtils.isSet(ident.getInode())){
      ident = ifac.loadFromCacheFromInode(inodeOrIdentifier);
    }
   
    if (ident == null || !InodeUtils.isSet(ident.getInode())) {
      try {
        Contentlet con = conAPI.find(inodeOrIdentifier, APILocator.getUserAPI().getSystemUser(), false);
        if (con != null && InodeUtils.isSet(con.getInode())) {
          ident = ifac.find(con.getIdentifier());
          return ident;
        }
      } catch (Exception e) {
        Logger.debug(this, "Unable to find inodeOrIdentifier as content : ", e);
      }
    } else {
      return ident;
    }

    try {
      ident = ifac.find(inodeOrIdentifier);
    } catch (DotHibernateException e) {
      Logger.debug(this, "Unable to find inodeOrIdentifier as identifier : ", e);
    }

   
    if (ident == null || !InodeUtils.isSet(ident.getInode())) {
       ident = ifac.find(InodeFactory.getInode(inodeOrIdentifier, Inode.class));
    }
   
    if (ident != null && InodeUtils.isSet(ident.getId()) ) {
      CacheLocator.getIdentifierCache().addIdentifierToCache(ident.getId(), inodeOrIdentifier);
    }
   
    return ident;
   
  }
View Full Code Here

  public Identifier loadFromDb(String id) throws DotDataException, DotStateException {
    return ifac.loadFromDb(id);
  }

  public Identifier save(Identifier id) throws DotDataException, DotStateException {
    Identifier ident = ifac.saveIdentifier(id);
    CacheLocator.getIdentifierCache().removeFromCacheByIdentifier(id.getId());
    return ident;
  }
View Full Code Here

  }

  @Override
  public Template copy(Template sourceTemplate, User user) throws DotDataException, DotSecurityException {

    Identifier id = APILocator.getIdentifierAPI().find(sourceTemplate.getIdentifier());

    Host  h = APILocator.getHostAPI().find(id.getHostId(), user, false);



    return copy(sourceTemplate, h, false, false, user, false);
View Full Code Here

    newTemplate.setBody(replaceWithNewContainerIds(newTemplate.getBody(), containerMappings));
    newTemplate.setDrawedBody(replaceWithNewContainerIds(newTemplate.getDrawedBody(), containerMappings));

    if (isNew) {
      // creates new identifier for this webasset and persists it
      Identifier newIdentifier = com.dotmarketing.business.APILocator.getIdentifierAPI().createNew(newTemplate, destination);
      Logger.debug(TemplateFactory.class, "Parent newIdentifier=" + newIdentifier.getInode());

      newTemplate.setIdentifier(newIdentifier.getInode());
      // persists the webasset
      save(newTemplate);
      List<Container> destinationContainers = getContainersInTemplate(newTemplate, user, respectFrontendRoles);
      associateContainers(destinationContainers, newTemplate);

      //Copy the host again
      newIdentifier.setHostId(destination.getIdentifier());
    } else {
      saveTemplate(newTemplate, destination, user, respectFrontendRoles);
    }

    APILocator.getVersionableAPI().setWorking(newTemplate);
View Full Code Here


  public Template saveTemplate(Template template, Host destination, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException {
    boolean existingId=false, existingInode=false;
      if(UtilMethods.isSet(template.getIdentifier())) {
        Identifier ident=APILocator.getIdentifierAPI().find(template.getIdentifier());
        existingId = ident==null || !UtilMethods.isSet(ident.getId());
    }

      if(UtilMethods.isSet(template.getInode())) {
          try {
              Template existing=(Template) HibernateUtil.load(Template.class, template.getInode());
              existingInode = existing==null || !UtilMethods.isSet(existing.getInode());
          }
          catch(Exception ex) {
              existingInode=true;
          }
      }

      Template oldTemplate = !existingId && UtilMethods.isSet(template.getIdentifier())
        ?findWorkingTemplate(template.getIdentifier(), user, respectFrontendRoles)
            :null;


    if ((oldTemplate != null) && InodeUtils.isSet(oldTemplate.getInode())) {
      if (!permissionAPI.doesUserHavePermission(oldTemplate, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
        throw new DotSecurityException("You don't have permission to read the source file.");
      }
    }

    if (!permissionAPI.doesUserHavePermission(destination, PermissionAPI.PERMISSION_CAN_ADD_CHILDREN, user, respectFrontendRoles)) {
      throw new DotSecurityException("You don't have permission to wirte in the destination folder.");
    }

    if (!permissionAPI.doesUserHavePermissions(PermissionableType.TEMPLATES, PermissionAPI.PERMISSION_EDIT, user)) {
      throw new DotSecurityException("You don't have permission to edit templates.");
    }


    //gets identifier from the current asset
    Identifier identifier = null;
    if (oldTemplate != null) {
      templateFactory.deleteFromCache(oldTemplate);
      identifier = identifierAPI.findFromInode(oldTemplate.getIdentifier());
    }
    else{
      identifier = (!existingId) ? APILocator.getIdentifierAPI().createNew(template, destination) :
                                   APILocator.getIdentifierAPI().createNew(template, destination, template.getIdentifier());
      template.setIdentifier(identifier.getId());
    }
    template.setModDate(new Date());
    template.setModUser(user.getUserId());

    //we need to replace older container parse syntax with updated syntax
View Full Code Here

TOP

Related Classes of com.dotmarketing.beans.Identifier

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.