Package com.dotmarketing.portlets.contentlet.business

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


   * @throws DotSecurityException
   * @throws DotDataException
   */
  public static boolean sendForgotPassword(User user, String newPassword, String hostId) throws DotDataException, DotSecurityException {

    HostAPI hostAPI = APILocator.getHostAPI();

    // build a decent default context
    Context context = VelocityUtil.getBasicContext();
    context.put("user", user);
    context.put("UtilMethods", new UtilMethods());
    context.put("language", "1");
    context.put("password", newPassword);

    Host host = hostAPI.find(hostId, user, true);
    context.put("host", host);

    StringWriter writer = new StringWriter();

    String idInode = APILocator.getIdentifierAPI().find(host, Config
View Full Code Here


     * @throws DotStateException
     * @throws DotSecurityException
     */
    private Boolean moveFile ( File file, Folder parent, Host host ) throws DotStateException, DotDataException, DotSecurityException {

        HostAPI hostAPI = APILocator.getHostAPI();

        //Find file identifier
        Identifier identifier = com.dotmarketing.business.APILocator.getIdentifierAPI().find( file );

        // gets working container
        File workingWebAsset = (File) APILocator.getVersionableAPI().findWorkingVersion( identifier, APILocator.getUserAPI().getSystemUser(), false );
        // gets live container
        File liveWebAsset = (File) APILocator.getVersionableAPI().findLiveVersion( identifier, APILocator.getUserAPI().getSystemUser(), false );

        // checks if another identifer with the same name exists in the same
        Boolean fileNameExists;
        if ( parent != null ) {
            fileNameExists = fileNameExists( parent, file.getFileName() );
        } else {
            fileNameExists = fileNameExists( APILocator.getFolderAPI().findSystemFolder(), file.getFileName() );
        }
        if ( fileNameExists ) {
            return false;
        }

        // assets cache
        if ( (liveWebAsset != null) && (InodeUtils.isSet( liveWebAsset.getInode() )) ) {
            LiveCache.removeAssetFromCache( liveWebAsset );
        }
        WorkingCache.removeAssetFromCache( workingWebAsset );

        // gets old parent
        Folder oldParent = APILocator.getFolderAPI().findParentFolder( workingWebAsset, APILocator.getUserAPI().getSystemUser(), false );

        /*oldParent.deleteChild(workingWebAsset);
          if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) {
              oldParent.deleteChild(liveWebAsset);
          }
          //add new Parent
          parent.addChild(workingWebAsset);
          if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) {
              parent.addChild(liveWebAsset);
          }*/

        // gets identifier for this webasset and changes the uri and persists it
        User systemUser;
        try {
            systemUser = APILocator.getUserAPI().getSystemUser();
            if ( host == null ) {
                host = hostAPI.findParentHost( parent, systemUser, false );
            }
        } catch ( DotDataException e ) {
            Logger.error( FileFactory.class, e.getMessage(), e );
            throw new DotRuntimeException( e.getMessage(), e );

View Full Code Here

    UserWebAPI userWebAPI = WebAPILocator.getUserWebAPI();
    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();

    UserAPI userAPI = APILocator.getUserAPI();
    HostAPI hostAPI = APILocator.getHostAPI();
    FolderAPI folderAPI = APILocator.getFolderAPI();

    //Retrieving the current user
    User user = userWebAPI.getLoggedInUser(request);
    User systemUser = userAPI.getSystemUser();
    boolean respectFrontendRoles = !userWebAPI.isLoggedToBackend(request);

    Set<Object> permAssets = new HashSet<Object>();
    HashMap<String, List<Permission>> permByInode = new HashMap<String, List<Permission>>();

    RoleAPI roleAPI = APILocator.getRoleAPI();
    PermissionAPI permAPI = APILocator.getPermissionAPI();
    Host systemHost = hostAPI.findSystemHost(systemUser, false);

    Role role = roleAPI.loadRoleById(roleId);

    List<Permission> perms = permAPI.getPermissionsByRole(role, true, true);

    for(Permission p : perms) {
      List<Permission> permList = permByInode.get(p.getInode());
      if(permList == null) {
        permList = new ArrayList<Permission>();
        permByInode.put(p.getInode(), permList);
      }
      permList.add(p);
      Identifier ident = APILocator.getIdentifierAPI().findFromInode(p.getInode());
      if(ident.getAssetType().equals("folder")) {
        Folder f =  APILocator.getFolderAPI().find(p.getInode(), systemUser, respectFrontendRoles);
        permAssets.add(f);
      } else {
        Host h = hostAPI.find(p.getInode(), systemUser, respectFrontendRoles);
        if(h != null) {
          permAssets.add(h);
        }
      }
    }

    List<Map<String, Object>> hostMaps = new ArrayList<Map<String,Object>>();
    List<Map<String, Object>> folderMaps = new ArrayList<Map<String,Object>>();
    boolean systemHostInList = false;
    for(Object i : permAssets) {
      if(i instanceof Host && ((Host)i).isSystemHost())
        systemHostInList = true;
      Map<String, Object> assetMap = i instanceof Host?((Host)i).getMap():((Inode)i).getMap();
      String assetId = i instanceof Host?((Host)i).getIdentifier():((Inode)i).getInode();
      List<Map<String, Object>> permissionsList = new ArrayList<Map<String,Object>>();
      for(Permission p: permByInode.get(assetId)) {
        permissionsList.add(p.getMap());
      }
      assetMap.put("permissions", permissionsList);
      if(i instanceof Host) {
        assetMap.put("type", "host");
        hostMaps.add(assetMap);
      } else {
        Folder f = (Folder) i;
        Identifier id = APILocator.getIdentifierAPI().find(f);
        String hostId = f.getHostId();
        Host h = hostAPI.find(hostId, systemUser, false);
        assetMap.put("fullPath", h.getHostname() + ":" + id.getParentPath() + f.getName());
        folderMaps.add(assetMap);
      }
      boolean permissionToEditPermissions = permAPI.doesUserHavePermission((Permissionable)i, PermissionAPI.PERMISSION_EDIT_PERMISSIONS, user, respectFrontendRoles);
      assetMap.put("permissionToEditPermissions", permissionToEditPermissions);
View Full Code Here

  public void saveRolePermission(String roleId, String folderHostId, Map<String, String> permissions, boolean cascade) throws DotDataException, DotSecurityException, PortalException, SystemException {

    Logger.info(this, "Applying role permissions for role " + roleId + " and folder/host id " + folderHostId);

    UserAPI userAPI = APILocator.getUserAPI();
    HostAPI hostAPI = APILocator.getHostAPI();
    FolderAPI folderAPI = APILocator.getFolderAPI();

    HibernateUtil.startTransaction();
    //Retrieving the current user
    User systemUser = userAPI.getSystemUser();
    boolean respectFrontendRoles = false;

    PermissionAPI permissionAPI = APILocator.getPermissionAPI();
    Host host = hostAPI.find(folderHostId, systemUser, false);
    Folder folder = null;
    if(host == null) {
      folder =APILocator.getFolderAPI().find(folderHostId, APILocator.getUserAPI().getSystemUser(), false);
    }
    Permissionable permissionable = host == null?folder:host;
View Full Code Here


  }

  public List<Map<String, Object>> getCurrentCascadePermissionsJobs () throws DotDataException, DotSecurityException {
    HostAPI hostAPI = APILocator.getHostAPI();
    FolderAPI folderAPI = APILocator.getFolderAPI();
    RoleAPI roleAPI = APILocator.getRoleAPI();
    List<ScheduledTask> tasks = CascadePermissionsJob.getCurrentScheduledJobs();
    List<Map<String, Object>> scheduled = new ArrayList<Map<String, Object>>();
    for (ScheduledTask task : tasks) {
      Map<String, Object> taskMap = new HashMap<String, Object>();
      Map<String, Object> props = task.getProperties();
      String permissionableId = (String) props.get("permissionableId");
      String roleId = (String) props.get("roleId");
      if(permissionableId == null || roleId == null)
        continue;
      Host host = hostAPI.find(permissionableId, APILocator.getUserAPI().getSystemUser(), false);
      if(host == null) {
        Folder folder = APILocator.getFolderAPI().find(permissionableId, APILocator.getUserAPI().getSystemUser(), false);
        if(folder == null)
          continue;
        taskMap.put("folder", folder.getMap());
        host = hostAPI.findParentHost(folder,APILocator.getUserAPI().getSystemUser(), false);
        taskMap.put("host", host.getMap());
      } else {
        taskMap.put("host", host.getMap());
      }
      Role role = roleAPI.loadRoleById(roleId);
View Full Code Here

    //Retrieving the current user
    User user = userWebAPI.getLoggedInUser(request);
    boolean respectFrontendRoles = !userWebAPI.isLoggedToBackend(request);

        HostAPI hostAPI = APILocator.getHostAPI();

    Permissionable perm = null;

    //Determining the type

    //Host?
    perm = hostAPI.find(assetId, user, respectFrontendRoles);
    if(perm == null) {
      //Content?
      ContentletAPI contAPI = APILocator.getContentletAPI();
      try {
        perm = contAPI.findContentletByIdentifier(assetId, false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, respectFrontendRoles);
View Full Code Here

    return hrs;
  }

  private List<Host> listHosts(){
      User user=(User)HttpManager.request().getAuthorization().getTag();
    HostAPI hostAPI = APILocator.getHostAPI();
    List<Host> hosts;
    try {
      hosts = hostAPI.findAll(user, false);
      hosts.remove(APILocator.getHostAPI().findSystemHost());
    } catch (DotDataException e) {
      Logger.error(WebdavRootResourceImpl.class, e.getMessage(), e);
      throw new DotRuntimeException(e.getMessage(), e);
    } catch (DotSecurityException e) {
View Full Code Here

            } catch (Exception e) {
                Logger.debug(this, "InitThread broke:", e);
            }
            try{

              HostAPI hostAPI = APILocator.getHostAPI();
                String defaultHost = hostAPI.findDefaultHost(APILocator.getUserAPI().getSystemUser(), false).getHostname();
                StringBuilder sb = new StringBuilder();
                List<Host> hosts = hostAPI.findAll(APILocator.getUserAPI().getSystemUser(), false);
                for (Host h : hosts) {
                  if(!"System Host".equals(h.getHostname())){
                    sb.append(h.getHostname() + "\n");
                  }
                    if (UtilMethods.isSet(h.getAliases())) {
View Full Code Here

  }

  public void loadBackEndFiles(String pluginId) throws IOException, DotDataException{
    try{
     
      HostAPI hostAPI = APILocator.getHostAPI();
     
      User systemUser = APILocator.getUserAPI().getSystemUser();
      JarFile jar = new JarFile(new File(pluginJarDir.getPath() + File.separator + "plugin-" + pluginId + ".jar"));
      List<Host> hostList = new ArrayList<Host>();

      String hosts = loadPluginConfigProperty(pluginId, "hosts.name");
      if(UtilMethods.isSet(hosts)){
        for(String hostname : hosts.split(",")){ 
          Host host = hostAPI.findByName(hostname, systemUser, false);
          hostList.add(host);
        }
      }else{
        Host host = hostAPI.findDefaultHost(systemUser, false);
        hostList.add(host);
      }

      Enumeration resources = jar.entries();
      while(resources.hasMoreElements()){
View Full Code Here

  }

  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors ae = new ActionErrors();
    try {
      HostAPI hostAPI = APILocator.getHostAPI();
      User systemUser = APILocator.getUserAPI().getSystemUser();
      if (request.getParameter("cmd") != null && request.getParameter("cmd").equals(Constants.ADD)) {
        String inode = request.getParameter("parent");
        Folder parentFolder = APILocator.getFolderAPI().find(inode, systemUser, false);
        if (!InodeUtils.isSet(parentFolder.getInode())) {
          Host host;
          host = (Host) hostAPI.find(inode, systemUser, false);
          if (host != null) {
            ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.folder.ishostfolder"));
          }
        }
      }
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.