Package com.dotcms.publisher.environment.bean

Examples of com.dotcms.publisher.environment.bean.Environment


            return;
          }

          String name = request.getParameter("environmentName");

          Environment existingEnv = APILocator.getEnvironmentAPI().findEnvironmentByName(name);

          if(existingEnv!=null) {
            Logger.info(getClass(), "Can't save Environment. An Environment with the given name already exists. ");
            User user = getUser();
          response.getWriter().println("FAILURE: " + LanguageUtil.get(user, "publisher_Environment_name_exists"));
          return;
          }

          String whoCanUseTmp = request.getParameter("whoCanUse");

          Environment environment = new Environment();
          environment.setName(name);
          environment.setPushToAll("pushToAll".equals(request.getParameter("pushType")));

          List<String> whoCanUse = Arrays.asList(whoCanUseTmp.split(","));
          List<Permission> permissions = new ArrayList<Permission>();

      for (String perm : whoCanUse) {
        if(!UtilMethods.isSet(perm)){
          continue;
        }

        Role test = resolveRole(perm);
        Permission p = new Permission(environment.getId(), test.getId(), PermissionAPI.PERMISSION_USE);

        boolean exists=false;
        for(Permission curr : permissions)
            exists=exists || curr.getRoleId().equals(p.getRoleId());
View Full Code Here


            //Reading the parameters
          String identifier = request.getParameter("identifier");
          String name = request.getParameter("environmentName");

            //Verify the environment exist
            Environment existingEnv = APILocator.getEnvironmentAPI().findEnvironmentByName( name );
            if ( existingEnv != null && !existingEnv.getId().equals( identifier ) ) {
                Logger.info( getClass(), "Can't save Environment. An Environment with the given name already exists. " );
                User user = getUser();
                response.getWriter().println( "FAILURE: " + LanguageUtil.get( user, "publisher_Environment_name_exists" ) );
                return;
            }

          String whoCanUseTmp = request.getParameter("whoCanUse");

          Environment environment = new Environment();
          environment.setId(identifier);
          environment.setName(name);
          environment.setPushToAll("pushToAll".equals(request.getParameter("pushType")));

          List<String> whoCanUse = Arrays.asList(whoCanUseTmp.split(","));
          List<Permission> permissions = new ArrayList<Permission>();

      for (String perm : whoCanUse) {
        if(!UtilMethods.isSet(perm)){
          continue;
        }

        Role test = resolveRole(perm);
        Permission p = new Permission(environment.getId(), test.getId(), PermissionAPI.PERMISSION_USE);

        boolean exists=false;
        for(Permission curr : permissions)
            exists=exists || curr.getRoleId().equals(p.getRoleId());

        if(!exists)
            permissions.add(p);
      }

          EnvironmentAPI eAPI = APILocator.getEnvironmentAPI();
      eAPI.updateEnvironment(environment, permissions);

            //If it was updated successfully lets set the session
            if ( UtilMethods.isSet( request.getSession().getAttribute( WebKeys.SELECTED_ENVIRONMENTS + getUser().getUserId() ) ) ) {

                //Get the selected environments from the session
                List<Environment> lastSelectedEnvironments = (List<Environment>) request.getSession().getAttribute( WebKeys.SELECTED_ENVIRONMENTS + getUser().getUserId() );

                Integer indexToReplace = null;
                for ( Environment currentEnv : lastSelectedEnvironments ) {
                    //Verify if the current env is on the ones stored in session
                    if ( currentEnv.getId().equals( environment.getId() ) ) {
                        indexToReplace = lastSelectedEnvironments.indexOf( currentEnv );
                    }
                }

                //If we found it lets use the updated
View Full Code Here

    for (PublishingEndPoint ep : endPoints) {
      APILocator.getPublisherEndPointAPI().deleteEndPointById(ep.getId());
    }

    Environment e = findEnvironmentById(id);

    APILocator.getPermissionAPI().removePermissions(e);

    // delete bundle-environment relationships
View Full Code Here

            List<String> whereToSend = Arrays.asList(whoToSendTmp.split(","));
            List<Environment> envsToSendTo = new ArrayList<Environment>();

            // Lists of Environments to push to
            for (String envId : whereToSend) {
              Environment e = APILocator.getEnvironmentAPI().findEnvironmentById(envId);

              if(e!=null) {
                envsToSendTo.add(e);
              }
      }

            //Put the selected environments in session in order to have the list of the last selected environments
            request.getSession().setAttribute( WebKeys.SELECTED_ENVIRONMENTS + getUser().getUserId(), envsToSendTo );

            SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd-H-m" );
            Date publishDate = dateFormat.parse( _contentPushPublishDate + "-" + _contentPushPublishTime );

            List<String> ids;
            if ( _assetId.startsWith( "query_" ) ) { //Support for lucene queries

                String luceneQuery = _assetId.replace( "query_", "" );
                List<String> queries = new ArrayList<String>();
                queries.add( luceneQuery );
                ids = PublisherUtil.getContentIds( queries );

            } else {

                String[] _assetsIds = _assetId.split( "," );//Support for multiple ids in the assetIdentifier parameter
                List<String> assetsIds = Arrays.asList( _assetsIds );

                ids = getIdsToPush( assetsIds, null, _contentFilterDate, dateFormat );
            }

            //Response map with the status of the addContents operation (error messages and counts )
            Map<String, Object> responseMap = null;

            if ( _iWantTo.equals( RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH ) || _iWantTo.equals( RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH_AND_EXPIRE ) ) {
              Bundle bundle = new Bundle(null, publishDate, null, getUser().getUserId(), forcePush);
              APILocator.getBundleAPI().saveBundle(bundle, envsToSendTo);

                responseMap = publisherAPI.addContentsToPublish( ids, bundle.getId(), publishDate, getUser() );
            }
            if ( _iWantTo.equals( RemotePublishAjaxAction.DIALOG_ACTION_EXPIRE ) || _iWantTo.equals( RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH_AND_EXPIRE ) ) {
                if ( (!"".equals( _contentPushExpireDate.trim() ) && !"".equals( _contentPushExpireTime.trim() )) ) {
                    Date expireDate = dateFormat.parse( _contentPushExpireDate + "-" + _contentPushExpireTime );

                    Bundle bundle = new Bundle(null, publishDate, expireDate, getUser().getUserId(), forcePush);
                  APILocator.getBundleAPI().saveBundle(bundle, envsToSendTo);

                    responseMap = publisherAPI.addContentsToUnpublish( ids, bundle.getId(), expireDate, getUser() );
                }
            }

            //If we have errors lets return them in order to feedback the user
            if ( responseMap != null && !responseMap.isEmpty() ) {

                //Error messages
                JSONArray jsonErrors = new JSONArray( (ArrayList) responseMap.get( "errorMessages" ) );

                //Prepare the Json response
                JSONObject jsonResponse = new JSONObject();
                jsonResponse.put( "errorMessages", jsonErrors.toArray() );
                jsonResponse.put( "errors", responseMap.get( "errors" ) );
                jsonResponse.put( "total", responseMap.get( "total" ) );
                jsonResponse.put( "bundleId", responseMap.get( "bundleId" ) );

                //And send it back to the user
                response.getWriter().println( jsonResponse.toString() );
            }
        } catch ( Exception e ) {
            Logger.error( RemotePublishAjaxAction.class, e.getMessage(), e );
            response.sendError( HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error Publishing Bundle: " + e.getMessage() );
        }
    }
View Full Code Here

            List<String> whereToSend = Arrays.asList(whoToSendTmp.split(","));
            List<Environment> envsToSendTo = new ArrayList<Environment>();

            // Lists of Environments to push to
            for (String envId : whereToSend) {
              Environment e = APILocator.getEnvironmentAPI().findEnvironmentById(envId);

              if(e!=null && APILocator.getPermissionAPI().doesUserHavePermission(e, PermissionAPI.PERMISSION_USE, getUser())) {
                envsToSendTo.add(e);
              }
      }

            if(envsToSendTo.isEmpty()) {
                response.sendError(HttpServletResponse.SC_FORBIDDEN);
                return;
            }

            //Put the selected environments in session in order to have the list of the last selected environments
            request.getSession().setAttribute( WebKeys.SELECTED_ENVIRONMENTS + getUser().getUserId(), envsToSendTo );
            //Clean up the selected bundle
            request.getSession().removeAttribute( WebKeys.SELECTED_BUNDLE + getUser().getUserId() );

            SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd-H-m" );
            Date publishDate = dateFormat.parse( _contentPushPublishDate + "-" + _contentPushPublishTime );
            Bundle bundle = APILocator.getBundleAPI().getBundleById(bundleId);
            APILocator.getBundleAPI().saveBundleEnvironments(bundle, envsToSendTo);

            if ( _iWantTo.equals( RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH )) {
              bundle.setPublishDate(publishDate);
               APILocator.getBundleAPI().updateBundle(bundle);

               publisherAPI.publishBundleAssets(bundle.getId(), publishDate);

            } else if ( _iWantTo.equals( RemotePublishAjaxAction.DIALOG_ACTION_EXPIRE )) {
              if ( (!"".equals( _contentPushExpireDate.trim() ) && !"".equals( _contentPushExpireTime.trim() )) ) {
                    Date expireDate = dateFormat.parse( _contentPushExpireDate + "-" + _contentPushExpireTime );
                    bundle.setExpireDate(expireDate);
                  APILocator.getBundleAPI().updateBundle(bundle);

                  publisherAPI.unpublishBundleAssets(bundle.getId(), expireDate);
                }

            } else if(_iWantTo.equals( RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH_AND_EXPIRE ) ) {
                if ( (!"".equals( _contentPushExpireDate.trim() ) && !"".equals( _contentPushExpireTime.trim() )) ) {
                    Date expireDate = dateFormat.parse( _contentPushExpireDate + "-" + _contentPushExpireTime );
                    bundle.setPublishDate(publishDate);
                    bundle.setExpireDate(expireDate);
                  APILocator.getBundleAPI().updateBundle(bundle);

                  publisherAPI.publishAndExpireBundleAssets(bundle.getId(), publishDate, expireDate, getUser());
                }
            }

        } catch ( Exception e ) {
            Logger.error( RemotePublishAjaxAction.class, e.getMessage(), e );
            response.sendError( HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error Push Publishing Bundle: " + e.getMessage() );
        }
    }
View Full Code Here

    DotConnect dc = new DotConnect();
    dc.setSQL(SELECT_ALL_ENVIRONMENTS);
    List<Map<String, Object>> res = dc.loadObjectResults();

    for(Map<String, Object> row : res){
      Environment environment = PublisherUtil.getEnvironmentByMap(row);
      environments.add(environment);
    }

    return environments;
  }
View Full Code Here

    DotConnect dc = new DotConnect();
    dc.setSQL(SELECT_ENVIRONMENTS_WITH_SERVERS);
    List<Map<String, Object>> res = dc.loadObjectResults();

    for(Map<String, Object> row : res){
      Environment environment = PublisherUtil.getEnvironmentByMap(row);
      environments.add(environment);
    }

    return environments;
  }
View Full Code Here

  public Environment getEnvironmentById(String id) throws DotDataException {
    DotConnect dc = new DotConnect();
    dc.setSQL(SELECT_ENVIRONMENT_BY_ID);
    dc.addParam(id);
    List<Map<String, Object>> res = dc.loadObjectResults();
    Environment e = null;

    if(res!=null && !res.isEmpty()) {
      Map<String, Object> row = res.get(0);
      e = PublisherUtil.getEnvironmentByMap(row);
    }
View Full Code Here

  public Environment getEnvironmentByName(String name) throws DotDataException {
    DotConnect dc = new DotConnect();
    dc.setSQL(SELECT_ENVIRONMENT_BY_NAME);
    dc.addParam(name);
    List<Map<String, Object>> res = dc.loadObjectResults();
    Environment e = null;

    if(res!=null && !res.isEmpty()) {
      Map<String, Object> row = res.get(0);
      e = PublisherUtil.getEnvironmentByMap(row);
    }
View Full Code Here

    DotConnect dc = new DotConnect();
    dc.setSQL(SELECT_ENVIRONMENTS_BY_ROLE_ID);
    dc.addParam(roleId);
    List<Map<String, Object>> res = dc.loadObjectResults();
    for(Map<String, Object> row : res){
      Environment environment = PublisherUtil.getEnvironmentByMap(row);
      environments.add(environment);
    }
    return environments;
  }
View Full Code Here

TOP

Related Classes of com.dotcms.publisher.environment.bean.Environment

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.