]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
Merge branch 'botgarden_profile' into botgarden_profile-2
authorremillet <remillet@yahoo.com>
Mon, 27 Mar 2017 21:52:02 +0000 (14:52 -0700)
committerremillet <remillet@yahoo.com>
Mon, 27 Mar 2017 21:52:02 +0000 (14:52 -0700)
Conflicts:
services/batch/service/src/main/java/org/collectionspace/services/batch/AbstractBatchInvocable.java
services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/CreateAndLinkLoanOutBatchJob.java

1  2 
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
services/batch/service/pom.xml
services/batch/service/src/main/java/org/collectionspace/services/batch/AbstractBatchInvocable.java
services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/CreateAndLinkLoanOutBatchJob.java
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java

Simple merge
index c487489a7225a6e29bc291f86772d5b9ee4f24d0,d612fc149a895a81b83d18372833f5bc53f84cfc..a61886197e3f8de96e9ee62339e437ad3bcd40b9
@@@ -37,15 -37,17 +38,15 @@@ public abstract class AbstractBatchInvo
      public final int INT_ERROR_STATUS = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
      protected final String CSID_VALUES_NOT_PROVIDED_IN_INVOCATION_CONTEXT =
              "Could not find required CSID values in the invocation context for this batch job.";
 +    
 +    private ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx;
      private List<String> invocationModes;
-     private ResourceMap resourceMap;
+     private ResourceMap<PoxPayloadIn, PoxPayloadOut> resourceMap;
 -    private InvocationContext invocationCtx;
 -    private ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx;
 -    private String tenantId;
  
 -
 -    private int completionStatus;
 -    private InvocationResults results;
 -    private InvocationError errorInfo;
 -    final Logger logger = LoggerFactory.getLogger(AbstractBatchInvocable.class);
 +    protected InvocationContext invocationCtx;
 +    protected int completionStatus;
 +    protected InvocationResults results;
 +    protected InvocationError errorInfo;
  
      public AbstractBatchInvocable() {
          init();
index aa38ece22be617d88a78da17fb7f82097174cdc1,5a5dd2d49f7ef2217d046099caff07df3ffa7ee9..96deb17841c119c806a40aefa18d4e62be8a769a
@@@ -73,9 -74,53 +75,49 @@@ public class BatchResource extends Nuxe
      @Override
      //public Class<BatchCommon> getCommonPartClass() {
      public Class getCommonPartClass() {
 -      try {
 -            return Class.forName("org.collectionspace.services.batch.BatchCommon");//.class;
 -        } catch (ClassNotFoundException e){
 -            return null;
 -        }
 +      return BatchCommon.class;
      }
      
 -      // FIXME: Resource classes should not be invoking handlers directly.  This resource method should follow the conventions used by
++      /**
+       // other resource methods and use the getRepositoryClient() methods.
+       @Override
+     protected AbstractCommonList getCommonList(UriInfo ui) {
+         try {
+             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+             MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
+             DocumentHandler handler = createDocumentHandler(ctx);
+             String docType = queryParams.getFirst(IQueryManager.SEARCH_TYPE_DOCTYPE);
+             String mode = queryParams.getFirst(IQueryManager.SEARCH_TYPE_INVOCATION_MODE);
+             String whereClause = null;
+             DocumentFilter documentFilter = null;
+             String common_part = ctx.getCommonPartLabel();
+                       
+             if (docType != null && !docType.isEmpty()) {
+                 whereClause = QueryManager.createWhereClauseForInvocableByDocType(
+                               common_part, docType);
+                 documentFilter = handler.getDocumentFilter();
+                 documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
+             }
+                       
+             if (mode != null && !mode.isEmpty()) {
+                 whereClause = QueryManager.createWhereClauseForInvocableByMode(
+                               common_part, mode);
+                 documentFilter = handler.getDocumentFilter();
+                 documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
+             }
+                       
+             if (whereClause !=null && logger.isDebugEnabled()) {
+                 logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
+             }
+                       
+             getRepositoryClient(ctx).getFiltered(ctx, handler);
+             AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList();
+             return list;
+         } catch (Exception e) {
+             throw bigReThrow(e, ServiceMessages.LIST_FAILED);
+         }
+     }
+       
        /**
         * Gets the authorityItem list for the specified authority
         * If partialPerm is specified, keywords will be ignored.
index 52f75556db7e49113e75ff99be1192bd236f6805,4529bcf690468b784e3c1ba91d1a4a2ad4f88ecc..86caddda40d52d89faed88da616267f013cc3232
@@@ -66,164 -56,31 +66,163 @@@ public class BatchDocumentModelHandler 
        private final Logger logger = LoggerFactory.getLogger(BatchDocumentModelHandler.class);
  
        protected final int BAD_REQUEST_STATUS = Response.Status.BAD_REQUEST.getStatusCode();
 -
 -      public InvocationResults invokeBatchJob(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String csid,
 -                      ResourceMap<PoxPayloadIn, PoxPayloadOut> resourceMap, InvocationContext invocationCtx) throws Exception {
 -
 -              String invocationMode = invocationCtx.getMode();
 -              String modeProperty = null;
 -              boolean checkDocType = true;
 +      
 +      /**
 +       * Return true if the batch job supports the requested mode.
 +       * @param invocationCtx
 +       * @param batchCommon
 +       * @return
 +       * @throws BadRequestException 
 +       */
 +      protected boolean supportsInvokationMode(InvocationContext invocationCtx, BatchCommon batchCommon) throws BadRequestException {
 +              boolean result = false;
 +              
 +              String invocationMode = invocationCtx.getMode().toLowerCase();
                if (BatchInvocable.INVOCATION_MODE_SINGLE.equalsIgnoreCase(invocationMode)) {
 -                      modeProperty = BatchJAXBSchema.SUPPORTS_SINGLE_DOC;
 +                      result = batchCommon.isSupportsSingleDoc(); //BatchJAXBSchema.SUPPORTS_SINGLE_DOC;
                } else if (BatchInvocable.INVOCATION_MODE_LIST.equalsIgnoreCase(invocationMode)) {
 -                      modeProperty = BatchJAXBSchema.SUPPORTS_DOC_LIST;
 +                      result = batchCommon.isSupportsDocList(); //BatchJAXBSchema.SUPPORTS_DOC_LIST;
                } else if (BatchInvocable.INVOCATION_MODE_GROUP.equalsIgnoreCase(invocationMode)) {
 -                      modeProperty = BatchJAXBSchema.SUPPORTS_GROUP;
 +                      result = batchCommon.isSupportsGroup(); //BatchJAXBSchema.SUPPORTS_GROUP;
                } else if (Invocable.INVOCATION_MODE_NO_CONTEXT.equalsIgnoreCase(invocationMode)) {
 -                      modeProperty = InvocableJAXBSchema.SUPPORTS_NO_CONTEXT;
 -                      checkDocType = false;
 +                      result = batchCommon.isSupportsNoContext(); //InvocableJAXBSchema.SUPPORTS_NO_CONTEXT;
                } else {
 -                      throw new BadRequestException("BatchResource: unknown Invocation Mode: " + invocationMode);
 +                      String msg = String.format("BatchResource: Unknown invocation mode '%s' requested trying to invoke batch job '%s'.",
 +                                      invocationMode, batchCommon.getName());
 +                      throw new BadRequestException(msg);
 +              }
 +              
 +              return result;
 +      }
 +      
 +      /**
 +       * Returns true if we found any required permissions.
 +       * 
 +       * @param batchCommon
 +       * @return
 +       */
 +      private boolean hasRequiredPermissions(BatchCommon batchCommon) {
 +              boolean result = false;
 +              
 +              try {
 +                      result = batchCommon.getResourceActionGroupList().getResourceActionGroup().size() > 0;
 +              } catch (NullPointerException e) {
 +                      // ignore exception, we're just testing to see if we have any list elements
 +              }
 +              
 +              return result;
 +      }
 +      
 +      /**
 +       * Returns true if we found any required roles.
 +       * 
 +       * @param batchCommon
 +       * @return
 +       */
 +      private boolean hasRequiredRoles(BatchCommon batchCommon) {
 +              boolean result = false;
 +              
 +              try {
 +                      result = batchCommon.getForRoles().getRoleDisplayName().size() > 0;
 +              } catch (NullPointerException e) {
 +                      // ignore exception, we're just testing to see if we have any list elements
 +              }
 +              
 +              return result;
 +      }
 +
 +      /**
 +       * The current user is authorized to run the batch job if:
 +       *      1. No permissions or roles are specified in the batch job
 +       *  2. No roles are specified, but permissions are specified and the current user has those permissions
 +       *  3. Roles are specified and the current user is a member of at least one of the roles.
 +       * 
 +       * @param batchCommon
 +       * @return
 +       */
 +      protected boolean isAuthoritzed(BatchCommon batchCommon) {
 +              boolean result = true;
 +              
 +              if (hasRequiredRoles(batchCommon)) { 
 +                      result = isAuthorizedWithRoles(batchCommon);
 +              } else if (hasRequiredPermissions(batchCommon)) {
 +                      result = isAuthoritzedWithPermissions(batchCommon);
 +              }
 +                              
 +              return result;
 +      }
 +      
 +      protected boolean isAuthorizedWithRoles(BatchCommon batchCommon) {
 +              boolean result = false;
 +              
 +              ForRoles forRolesList = batchCommon.getForRoles();
 +              if (forRolesList != null) {
 +                      AccountResource accountResource = new AccountResource();
 +                      List<String> roleDisplayNameList = accountResource.getAccountRoles(AuthN.get().getUserId(), AuthN.get().getCurrentTenantId());
 +                      for (String target : forRolesList.getRoleDisplayName()) {
 +                              if (roleDisplayNameList.contains(target)) {
 +                                      result = true;
 +                                      break;
 +                              }
 +                      }
                }
 +              
 +              return result;
 +      }
 +      
 +      /**
 +       * Check to see if the current user is authorized to run/invoke this batch job.  If the batch job
 +       * did not specify any permissions, we assume that the current user is authorized to run the job.
 +       * @param batchCommon
 +       * @return
 +       */
 +      protected boolean isAuthoritzedWithPermissions(BatchCommon batchCommon) {
 +              boolean result = true;
 +              
 +              ResourceActionGroupList resourceActionGroupList = batchCommon.getResourceActionGroupList();
 +              if (resourceActionGroupList != null) {
 +                      String tenantId = AuthN.get().getCurrentTenantId();
 +                      for (ResourceActionGroup resourceActionGroup: resourceActionGroupList.getResourceActionGroup()) {
 +                              String resourceName = resourceActionGroup.getResourceName();
 +                              ActionGroup actionGroup = ActionGroup.creatActionGroup(resourceActionGroup.getActionGroup());
 +                              for (ActionType actionType: actionGroup.getActions()) {
 +                                      CSpaceResource res = new URIResourceImpl(tenantId, resourceName, AuthZ.getMethod(actionType));
 +                                      if (AuthZ.get().isAccessAllowed(res) == false) {
 +                                              return false;
 +                                      }
 +                              }
 +                      }
 +              }
 +              
 +              return result;
 +      }
 +      
 +      /**
 +       * Returns a copy of the incoming list of strings all lower-cased.  Also removes any duplicates.
 +       * 
 +       * @param listOfStrings
 +       * @return
 +       */
 +      private List<String> toLowerCase(List<String> listOfStrings) {
 +              List<String> result = null;
 +              
 +              if (listOfStrings != null) {
 +                      Set<String> stringSet = new HashSet<String>();
 +                      for (String s : listOfStrings) {
 +                              stringSet.add(s.toLowerCase());
 +                      }
 +                      result = new ArrayList<String>(stringSet);
 +              }
 +              
 +              return result;
 +      }
  
 -              //
 -              // Acquire a repository session handle if we don't already have one
 +      public InvocationResults invokeBatchJob(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String csid,
 +                      ResourceMap resourceMap, InvocationContext invocationCtx, BatchCommon batchCommon) throws Exception {
 +              CoreSessionInterface repoSession = null;
                boolean releaseRepoSession = false;
 -              CoreSessionInterface repoSession = this.getRepositorySession();
 +
                RepositoryClientImpl repoClient = (RepositoryClientImpl) this.getRepositoryClient(ctx);
-               repoSession = this.getRepositorySession();
                if (repoSession == null) {
                        repoSession = repoClient.getRepositorySession(ctx);
                        releaseRepoSession = true;
index 4ac26db5bf0b1fae8c285655446d9e3280b27b95,b6053b06aa2a877bab0dd5de8959683b58c37ea0..0b94859e06a05381c96cbb077ed88c17676d1315
@@@ -15,14 -16,56 +15,14 @@@ import org.collectionspace.services.cli
  
  public class CreateAndLinkLoanOutBatchJob extends AbstractBatchInvocable {
  
 -      private static ArrayList<String> invocationModes = null;
 -      private InvocationContext invocationCtx;
 -      private int completionStatus;
 -      private InvocationResults results;
 -      private InvocationError errorInfo;
        private final String RELATION_TYPE = "affects"; 
-       private final String LOAN_DOCTYPE = "LoanOut"; 
+       private final String LOAN_DOCTYPE = "LoanOut";
        private final String RELATION_PREDICATE_DISP = "affects"; 
 -      protected final int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
 -      protected final int BAD_REQUEST_STATUS = Response.Status.BAD_REQUEST.getStatusCode();
 -      protected final int INT_ERROR_STATUS = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
        
        public CreateAndLinkLoanOutBatchJob() {
 -              CreateAndLinkLoanOutBatchJob.setupClassStatics();
 -              invocationCtx = null;
 -              completionStatus = STATUS_UNSTARTED;
 -              results = new InvocationResults();
 -              errorInfo = null;
 -      }
 -
 -      private static void setupClassStatics() {
 -              if(invocationModes == null ) {
 -                      invocationModes = new ArrayList<String>(1);
 -                      invocationModes.add(INVOCATION_MODE_SINGLE);
 -                      invocationModes.add(INVOCATION_MODE_LIST);
 -              }
 -      }
 -
 -      /**
 -       * @return a set of modes that this plugin can support on invocation. Must be non-empty.
 -       */
 -      public List<String> getSupportedInvocationModes() {
 -              return CreateAndLinkLoanOutBatchJob.invocationModes;
 +        setSupportedInvocationModes(Arrays.asList(INVOCATION_MODE_SINGLE, INVOCATION_MODE_LIST));
        }
        
 -    
 -    @Override
 -    public InvocationContext getInvocationContext() {
 -        return invocationCtx;
 -    }    
 -      
 -      /**
 -       * Sets the invocation context for the batch job. Called before run().
 -       * @param context an instance of InvocationContext.
 -       */
 -    @Override
 -      public void setInvocationContext(InvocationContext context) {
 -              this.invocationCtx = context;
 -      }
 -
        /**
         * The main work logic of the batch job. Will be called after setContext.
         */