Examples of PermissionAPI


Examples of com.dotmarketing.business.PermissionAPI

              try {
                  for ( String identifier : identifiers ) {

                      DotConnect dc = new DotConnect();
                      dc.setSQL( INSERTSQL );
                      PermissionAPI strPerAPI = APILocator.getPermissionAPI();

                      String type = "";

                      //First verify what kind of element we want to publish in order to avoid unnecessary calls
                      if ( identifier.contains( "user_" ) ) {//Trying to publish a user
                          type = "user";
                      } else if ( identifier.contains( ".jar" ) ) {//Trying to publish an OSGI jar bundle
                          type = "osgi";
                      } else {

                          Identifier iden = APILocator.getIdentifierAPI().find( identifier );

                          if ( !UtilMethods.isSet( iden.getId() ) ) { // we have an inode, not an identifier
                              try {
                                  // check if it is a structure
                                  Structure st = null;
                                  List<Structure> sts = StructureFactory.getStructures();
                                  for ( Structure s : sts ) {
                                      if ( s.getInode().equals( identifier ) ) {
                                          st = s;
                                      }
                                  }
                                  Folder folder;

                                  /**
                                   * ISSUE 2244: https://github.com/dotCMS/dotCMS/issues/2244
                                   *
                                   */
                                  // check if it is a category
                                  if ( CATEGORY.equals( identifier ) ) {
                                      type = "category";
                                  } else if ( UtilMethods.isSet( st ) ) {
                                      if ( !strPerAPI.doesUserHavePermission( st, PermissionAPI.PERMISSION_PUBLISH, user ) ) {
                                          //Generate and append the error message
                                          appendPermissionError( errorsList, user, "Structure", st.getName(), st.getIdentifier() );
                                          continue;
                                      }

                                      type = "structure";
                                  }

                                  // check if it is a folder
                                  else if ( UtilMethods.isSet( folder = APILocator.getFolderAPI().find( identifier, user, false ) ) ) {
                                      if ( !strPerAPI.doesUserHavePermission( folder, PermissionAPI.PERMISSION_PUBLISH, user ) ) {
                                          //Generate and append the error message
                                          appendPermissionError( errorsList, user, "Folder", folder.getName(), folder.getIdentifier() );
                                          continue;
                                      }

                                      type = "folder";
                                  }
                              } catch ( Exception ex ) {
                                if ( UtilMethods.isSet( APILocator.getWorkflowAPI().findScheme(identifier) )) {
                                    type = "workflow";
                                  }
                              }

                          } else {
                              if ( !strPerAPI.doesUserHavePermission( iden, PermissionAPI.PERMISSION_PUBLISH, user ) ) {
                                  //Generate and append the error message
                                  appendPermissionError( errorsList, user, iden.getAssetType(), null, iden.getId() );
                                  continue;
                              }
                              type = UtilMethods.isSet( APILocator.getHostAPI().find( identifier, user, false ) ) ? "host" : iden.getAssetType();
View Full Code Here

Examples of com.dotmarketing.business.PermissionAPI

    public void getParents () throws Exception {

        Long time = new Date().getTime();

        CategoryAPI categoryAPI = APILocator.getCategoryAPI();
        PermissionAPI permissionAPI = APILocator.getPermissionAPI();
        ContentletAPI contentletAPI = APILocator.getContentletAPI();

        List<Category> categories = new ArrayList<Category>();

        //***************************************************************
        //Creating new categories

        HibernateUtil.startTransaction();

        //Adding the parent category
        Category parentCategory = new Category();
        parentCategory.setCategoryName( "Movies" + time );
        parentCategory.setKey( "movies" + time );
        parentCategory.setCategoryVelocityVarName( "movies" + time );
        parentCategory.setSortOrder( (String) null );
        parentCategory.setKeywords( null );
        //Saving it
        categoryAPI.save( null, parentCategory, user, false );

        //Creating child categories
        //New Child category
        Category childCategory1 = new Category();
        childCategory1.setCategoryName( "Action" + time );
        childCategory1.setKey( "action" + time );
        childCategory1.setCategoryVelocityVarName( "action" + time );
        childCategory1.setSortOrder( (String) null );
        childCategory1.setKeywords( null );
        //Saving it
        categoryAPI.save( parentCategory, childCategory1, user, false );
        categories.add( childCategory1 );
        //New Child category
        Category childCategory2 = new Category();
        childCategory2.setCategoryName( "Drama" + time );
        childCategory2.setKey( "drama" + time );
        childCategory2.setCategoryVelocityVarName( "drama" + time );
        childCategory2.setSortOrder( (String) null );
        childCategory2.setKeywords( null );
        //Saving it
        categoryAPI.save( parentCategory, childCategory2, user, false );
        categories.add( childCategory2 );

        HibernateUtil.commitTransaction();

        //***************************************************************
        //Verify If we find the parent for the categories we just added categories
        List<Category> parents = categoryAPI.getParents( childCategory1, user, false );
        assertNotNull( parents );
        assertTrue( parents.size() > 0 );
        assertEquals( parents.get( 0 ), parentCategory );

        parents = categoryAPI.getParents( childCategory2, user, false );
        assertNotNull( parents );
        assertTrue( parents.size() > 0 );
        assertEquals( parents.get( 0 ), parentCategory );

        //***************************************************************
        //Set up a new structure with categories

        HibernateUtil.startTransaction();

        //Create the new structure
        Structure testStructure = createStructure( "JUnit Test Categories Structure_" + String.valueOf( new Date().getTime() ), "junit_test_categories_structure_" + String.valueOf( new Date().getTime() ) );
        //Add a Text field
        Field textField = new Field( "JUnit Test Text", Field.FieldType.TEXT, Field.DataType.TEXT, testStructure, false, true, true, 1, false, false, false );
        FieldFactory.saveField( textField );
        //Add a Category field
        Field categoryField = new Field( "JUnit Movies", Field.FieldType.CATEGORY, Field.DataType.TEXT, testStructure, true, true, true, 2, false, false, true );
        categoryField.setValues( parentCategory.getInode() );
        FieldFactory.saveField( categoryField );

        //***************************************************************
        //Set up a content for the categories structure
        Contentlet contentlet = new Contentlet();
        contentlet.setStructureInode( testStructure.getInode() );
        contentlet.setHost( defaultHost.getIdentifier() );
        contentlet.setLanguageId( APILocator.getLanguageAPI().getDefaultLanguage().getId() );

        //Validate if the contenlet is OK
        contentletAPI.validateContentlet( contentlet, categories );

        //Saving the contentlet
        contentlet = APILocator.getContentletAPI().checkin( contentlet, categories, permissionAPI.getPermissions( contentlet, false, true ), user, false );
        APILocator.getContentletAPI().isInodeIndexed( contentlet.getInode() );
        APILocator.getVersionableAPI().setLive( contentlet );

        HibernateUtil.commitTransaction();

View Full Code Here

Examples of com.dotmarketing.business.PermissionAPI

     * @throws com.dotmarketing.exception.DotSecurityException
     *
     */
    protected static Structure createStructure ( String name, String structureVelocityVarName ) throws DotDataException, DotSecurityException {

        PermissionAPI permissionAPI = APILocator.getPermissionAPI();

        //Set up a test folder
        Folder testFolder = APILocator.getFolderAPI().createFolders( "/" + new Date().getTime() + "/", defaultHost, user, false );
        permissionAPI.permissionIndividually( permissionAPI.findParentPermissionable( testFolder ), testFolder, user, false );

        //Create the structure
        Structure testStructure = new Structure();

        testStructure.setDefaultStructure( false );
View Full Code Here

Examples of com.dotmarketing.business.PermissionAPI

      }

      conAPI.setContentletProperty(contentletComment, field, comment);

      // Add the permission
      PermissionAPI perAPI = APILocator.getPermissionAPI();
      List<Permission> pers = perAPI.getPermissions(commentsStructure);




      // new workflows
View Full Code Here

Examples of com.dotmarketing.business.PermissionAPI

        dh.setSQLQuery(sb.toString());

        dh.setFirstResult(internalOffset);
        dh.setMaxResults(internalLimit);
       
        PermissionAPI permAPI = APILocator.getPermissionAPI();
        List<WebAsset> list = dh.list();
        toReturn.addAll(permAPI.filterCollection(list, PermissionAPI.PERMISSION_READ, false, user));
        if(limit > 0 && toReturn.size() >= limit + offset)
          done = true;
        else if(list.size() < internalLimit)
          done = true;
       
View Full Code Here

Examples of com.dotmarketing.business.PermissionAPI

        dh.setSQLQuery(sb.toString());

        dh.setFirstResult(internalOffset);
        dh.setMaxResults(internalLimit);
       
        PermissionAPI permAPI = APILocator.getPermissionAPI();
        List<WebAsset> list = dh.list();
        toReturn.addAll(permAPI.filterCollection(list, PermissionAPI.PERMISSION_READ, false, user));
        if(limit > 0 && toReturn.size() >= limit + offset)
          done = true;
        else if(list.size() < internalLimit)
          done = true;
       
View Full Code Here

Examples of com.dotmarketing.business.PermissionAPI

      dh.setSQLQuery(sb.toString());
      int firstResult = 0;
      dh.setFirstResult(firstResult);
      dh.setMaxResults(MAX_LIMIT_COUNT);
     
      PermissionAPI permAPI = APILocator.getPermissionAPI();
      List<WebAsset> list = dh.list();
     
      int pos = 0;
      boolean offsetFound = false;
      while (UtilMethods.isSet(fromAssetId) && !offsetFound && (list != null) && (0 < list.size())) {
        pos = 0;
        for (WebAsset webAsset: list) {
          if (webAsset.getIdentifier().equals(fromAssetId)) {
            offsetFound = true;
            break;
          } else {
            ++pos;
          }
        }
       
        if (!offsetFound) {
          firstResult += MAX_LIMIT_COUNT;
          dh.setFirstResult(firstResult);
          list = dh.list();
        }
      }
     
      if ((pos == 0) && !offsetFound) {
        --pos;
        offsetFound = true;
      }
     
      List<WebAsset> result = new ArrayList<WebAsset>(limit);
     
      WebAsset webAsset;
      while (offsetFound && (result.size() < limit) && (list != null) && (0 < list.size())) {
        if (direction.equals(Direction.NEXT)) {
          ++pos;
          while ((result.size() < limit) && (pos < list.size())) {
            webAsset = (WebAsset) list.get(pos);
            if (permAPI.doesUserHavePermission(webAsset, PermissionAPI.PERMISSION_READ, user, false)) {
              result.add(webAsset);
            }
            ++pos;
          }
         
          if (result.size() < limit) {
            firstResult += MAX_LIMIT_COUNT;
            dh.setFirstResult(firstResult);
            list = dh.list();
            pos = -1;
          }
        } else {
          --pos;
          while ((result.size() < limit) && (-1 < pos)) {
            webAsset = (WebAsset) list.get(pos);
            if (permAPI.doesUserHavePermission(webAsset, PermissionAPI.PERMISSION_READ, user, false)) {
              result.add(webAsset);
            }
            --pos;
          }
         
View Full Code Here

Examples of com.dotmarketing.business.PermissionAPI

      dh.setSQLQuery(sb.toString());
      int firstResult = 0;
      dh.setFirstResult(firstResult);
      dh.setMaxResults(MAX_LIMIT_COUNT);
     
      PermissionAPI permAPI = APILocator.getPermissionAPI();
      List<WebAsset> list = dh.list();
     
      int pos = 0;
      boolean offsetFound = false;
      while (UtilMethods.isSet(fromAssetId) && !offsetFound && (list != null) && (0 < list.size())) {
        pos = 0;
        for (WebAsset webAsset: list) {
          if (webAsset.getIdentifier().equals(fromAssetId)) {
            offsetFound = true;
            break;
          } else {
            ++pos;
          }
        }
       
        if (!offsetFound) {
          firstResult += MAX_LIMIT_COUNT;
          dh.setFirstResult(firstResult);
          list = dh.list();
        }
      }
     
      if ((pos == 0) && !offsetFound) {
        --pos;
        offsetFound = true;
      }
     
      List<WebAsset> result = new ArrayList<WebAsset>(limit);
     
      WebAsset webAsset;
      while (offsetFound && (result.size() < limit) && (list != null) && (0 < list.size())) {
        if (direction.equals(Direction.NEXT)) {
          ++pos;
          while ((result.size() < limit) && (pos < list.size())) {
            webAsset = (WebAsset) list.get(pos);
            if (permAPI.doesUserHavePermission(webAsset, PermissionAPI.PERMISSION_READ, user, false)) {
              result.add(webAsset);
            }
            ++pos;
          }
         
          if (result.size() < limit) {
            firstResult += MAX_LIMIT_COUNT;
            dh.setFirstResult(firstResult);
            list = dh.list();
            pos = -1;
          }
        } else {
          --pos;
          while ((result.size() < limit) && (-1 < pos)) {
            webAsset = (WebAsset) list.get(pos);
            if (permAPI.doesUserHavePermission(webAsset, PermissionAPI.PERMISSION_READ, user, false)) {
              result.add(webAsset);
            }
            --pos;
          }
         
View Full Code Here

Examples of com.dotmarketing.business.PermissionAPI

     
      List<Map<String, String>> list = dc.loadResults();
      List<Permissionable> assetsList = new ArrayList<Permissionable>();
      WebAsset permissionable;
     
      PermissionAPI permAPI = APILocator.getPermissionAPI();
     
      while ((assetsList.size() < limit) && (list != null) && (0 < list.size())) {
        for (Map<String, String> map: list) {
          permissionable = (WebAsset) c.newInstance();
          permissionable.setIdentifier(map.get("identifier"));
          permissionable.setInode(map.get("inode"));
         
          if (permAPI.doesUserHavePermission(permissionable, PermissionAPI.PERMISSION_READ, user, false)) {
            assetsList.add(permissionable);
            if (limit < assetsList.size())
              break;
          }
        }
View Full Code Here

Examples of com.dotmarketing.business.PermissionAPI

          permissionable.setIdentifier(map.get("identifier"));
          permissionable.setInode(map.get("inode"));
          assetsList.add(permissionable);
        }
       
        PermissionAPI permAPI = APILocator.getPermissionAPI();
        toReturn.addAll(permAPI.filterCollection(assetsList, PermissionAPI.PERMISSION_READ, false, user));
        if(limit > 0 && toReturn.size() >= limit + offset)
          done = true;
        else if(assetsList.size() < internalLimit)
          done = true;
       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.