@Test public void testParametersHandling() throws Exception { Map<String, Serializable> params = new HashMap<>(); try { service.run(ctx, BulkRunAction.ID, params); fail("Expected exception"); } catch (OperationException e) { assertTrue(e.getMessage().contains("Failed to inject parameter 'action'")); } params.put("action", "foobar"); try { service.run(ctx, BulkRunAction.ID, params); fail("Expected exception"); } catch (NuxeoException e) { assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); } params.put("action", SetPropertiesAction.ACTION_NAME); try { service.run(ctx, BulkRunAction.ID, params); fail("Expected exception"); } catch (OperationException e) { assertEquals("Query and ProviderName cannot be both null", e.getMessage()); } params.put("query", "SELECT * FROM Document"); service.run(ctx, BulkRunAction.ID, params); params.put("query", "SELECT * FROM Document where ecm:parentId=?"); try { service.run(ctx, BulkRunAction.ID, params); fail("Expected exception"); } catch (OperationException e) { assertEquals("Query parameters could not be parsed", e.getMessage()); } params.remove("query"); params.put("providerName", "unknow provider name"); try { service.run(ctx, BulkRunAction.ID, params); fail("Expected exception"); } catch (OperationException e) { assertEquals("Could not get Provider Definition from either query or provider name", e.getMessage()); } params.put("providerName", "simpleProviderTest1"); service.run(ctx, BulkRunAction.ID, params); params.put("query", "SELECT * FROM Document"); params.put("parameters", "foobar"); try { service.run(ctx, BulkRunAction.ID, params); fail("Expected exception"); } catch (OperationException e) { assertEquals("Could not parse parameters, expecting valid json value", e.getMessage()); } }
@OperationMethod(asyncService = BulkService.class) public BulkStatus run() throws IOException, OperationException { if (!admin.getActions().contains(action)) { throw new NuxeoException("Action '" + action + "' not found", HttpServletResponse.SC_NOT_FOUND); } if (!admin.isHttpEnabled(action) && !session.getPrincipal().isAdministrator()) { throw new NuxeoException("Action '" + action + "' denied", HttpServletResponse.SC_FORBIDDEN); } if (query == null && providerName == null) { throw new OperationException("Query and ProviderName cannot be both null"); } PageProviderDefinition def = query != null ? PageProviderHelper.getQueryPageProviderDefinition(query) : PageProviderHelper.getPageProviderDefinition(providerName); if (def == null) { throw new OperationException("Could not get Provider Definition from either query or provider name"); } PageProvider<?> provider = PageProviderHelper.getPageProvider(session, def, namedParameters, null, null, null, null, null, quickFilters, queryParams != null ? queryParams.toArray(new String[0]) : null); query = PageProviderHelper.buildQueryStringWithAggregates(provider); if (query.contains("?")) { throw new OperationException("Query parameters could not be parsed"); } BulkCommand.Builder builder = new BulkCommand.Builder(action, query, session.getPrincipal().getName()); try { builder.params(BulkParameters.paramsToMap(parametersAsJson)); } catch (IOException e) { throw new OperationException("Could not parse parameters, expecting valid json value", e); } if (repositoryName != null) { builder.repository(repositoryName); } else { builder.repository(session.getRepositoryName()); } if (bucketSize > 0) { builder.bucket(bucketSize); } if (batchSize > 0) { builder.batch(batchSize); } String commandId = service.submit(builder.build()); return service.getStatus(commandId); }
BulkRunAction { @OperationMethod(asyncService = BulkService.class) public BulkStatus run() throws IOException, OperationException { if (!admin.getActions().contains(action)) { throw new NuxeoException("Action '" + action + "' not found", HttpServletResponse.SC_NOT_FOUND); } if (!admin.isHttpEnabled(action) && !session.getPrincipal().isAdministrator()) { throw new NuxeoException("Action '" + action + "' denied", HttpServletResponse.SC_FORBIDDEN); } if (query == null && providerName == null) { throw new OperationException("Query and ProviderName cannot be both null"); } PageProviderDefinition def = query != null ? PageProviderHelper.getQueryPageProviderDefinition(query) : PageProviderHelper.getPageProviderDefinition(providerName); if (def == null) { throw new OperationException("Could not get Provider Definition from either query or provider name"); } PageProvider<?> provider = PageProviderHelper.getPageProvider(session, def, namedParameters, null, null, null, null, null, quickFilters, queryParams != null ? queryParams.toArray(new String[0]) : null); query = PageProviderHelper.buildQueryStringWithAggregates(provider); if (query.contains("?")) { throw new OperationException("Query parameters could not be parsed"); } BulkCommand.Builder builder = new BulkCommand.Builder(action, query, session.getPrincipal().getName()); try { builder.params(BulkParameters.paramsToMap(parametersAsJson)); } catch (IOException e) { throw new OperationException("Could not parse parameters, expecting valid json value", e); } if (repositoryName != null) { builder.repository(repositoryName); } else { builder.repository(session.getRepositoryName()); } if (bucketSize > 0) { builder.bucket(bucketSize); } if (batchSize > 0) { builder.batch(batchSize); } String commandId = service.submit(builder.build()); return service.getStatus(commandId); } }
BulkRunAction { @OperationMethod(asyncService = BulkService.class) public BulkStatus run() throws IOException, OperationException { if (!admin.getActions().contains(action)) { throw new NuxeoException("Action '" + action + "' not found", HttpServletResponse.SC_NOT_FOUND); } if (!admin.isHttpEnabled(action) && !session.getPrincipal().isAdministrator()) { throw new NuxeoException("Action '" + action + "' denied", HttpServletResponse.SC_FORBIDDEN); } if (query == null && providerName == null) { throw new OperationException("Query and ProviderName cannot be both null"); } PageProviderDefinition def = query != null ? PageProviderHelper.getQueryPageProviderDefinition(query) : PageProviderHelper.getPageProviderDefinition(providerName); if (def == null) { throw new OperationException("Could not get Provider Definition from either query or provider name"); } PageProvider<?> provider = PageProviderHelper.getPageProvider(session, def, namedParameters, null, null, null, null, null, quickFilters, queryParams != null ? queryParams.toArray(new String[0]) : null); query = PageProviderHelper.buildQueryStringWithAggregates(provider); if (query.contains("?")) { throw new OperationException("Query parameters could not be parsed"); } BulkCommand.Builder builder = new BulkCommand.Builder(action, query, session.getPrincipal().getName()); try { builder.params(BulkParameters.paramsToMap(parametersAsJson)); } catch (IOException e) { throw new OperationException("Could not parse parameters, expecting valid json value", e); } if (repositoryName != null) { builder.repository(repositoryName); } else { builder.repository(session.getRepositoryName()); } if (bucketSize > 0) { builder.bucket(bucketSize); } if (batchSize > 0) { builder.batch(batchSize); } String commandId = service.submit(builder.build()); return service.getStatus(commandId); }  }
BulkRunAction { @OperationMethod(asyncService = BulkService.class) public BulkStatus run() throws IOException, OperationException { if (!admin.getActions().contains(action)) { throw new NuxeoException("Action '" + action + "' not found", HttpServletResponse.SC_NOT_FOUND); } if (!admin.isHttpEnabled(action) && !session.getPrincipal().isAdministrator()) { throw new NuxeoException("Action '" + action + "' denied", HttpServletResponse.SC_FORBIDDEN); } if (query == null && providerName == null) { throw new OperationException("Query and ProviderName cannot be both null"); } PageProviderDefinition def = query != null ? PageProviderHelper.getQueryPageProviderDefinition(query) : PageProviderHelper.getPageProviderDefinition(providerName); if (def == null) { throw new OperationException("Could not get Provider Definition from either query or provider name"); } PageProvider<?> provider = PageProviderHelper.getPageProvider(session, def, namedParameters, null, null, null, null, null, quickFilters, queryParams != null ? queryParams.toArray(new String[0]) : null); query = PageProviderHelper.buildQueryStringWithAggregates(provider); if (query.contains("?")) { throw new OperationException("Query parameters could not be parsed"); } BulkCommand.Builder builder = new BulkCommand.Builder(action, query, session.getPrincipal().getName()); try { builder.params(BulkParameters.paramsToMap(parametersAsJson)); } catch (IOException e) { throw new OperationException("Could not parse parameters, expecting valid json value", e); } if (repositoryName != null) { builder.repository(repositoryName); } else { builder.repository(session.getRepositoryName()); } if (bucketSize > 0) { builder.bucket(bucketSize); } if (batchSize > 0) { builder.batch(batchSize); } String commandId = service.submit(builder.build()); return service.getStatus(commandId); }  @OperationMethod(asyncService = BulkService.class) BulkStatus run(); }
BulkRunAction { @OperationMethod(asyncService = BulkService.class) public BulkStatus run() throws IOException, OperationException { if (!admin.getActions().contains(action)) { throw new NuxeoException("Action '" + action + "' not found", HttpServletResponse.SC_NOT_FOUND); } if (!admin.isHttpEnabled(action) && !session.getPrincipal().isAdministrator()) { throw new NuxeoException("Action '" + action + "' denied", HttpServletResponse.SC_FORBIDDEN); } if (query == null && providerName == null) { throw new OperationException("Query and ProviderName cannot be both null"); } PageProviderDefinition def = query != null ? PageProviderHelper.getQueryPageProviderDefinition(query) : PageProviderHelper.getPageProviderDefinition(providerName); if (def == null) { throw new OperationException("Could not get Provider Definition from either query or provider name"); } PageProvider<?> provider = PageProviderHelper.getPageProvider(session, def, namedParameters, null, null, null, null, null, quickFilters, queryParams != null ? queryParams.toArray(new String[0]) : null); query = PageProviderHelper.buildQueryStringWithAggregates(provider); if (query.contains("?")) { throw new OperationException("Query parameters could not be parsed"); } BulkCommand.Builder builder = new BulkCommand.Builder(action, query, session.getPrincipal().getName()); try { builder.params(BulkParameters.paramsToMap(parametersAsJson)); } catch (IOException e) { throw new OperationException("Could not parse parameters, expecting valid json value", e); } if (repositoryName != null) { builder.repository(repositoryName); } else { builder.repository(session.getRepositoryName()); } if (bucketSize > 0) { builder.bucket(bucketSize); } if (batchSize > 0) { builder.batch(batchSize); } String commandId = service.submit(builder.build()); return service.getStatus(commandId); }  @OperationMethod(asyncService = BulkService.class) BulkStatus run(); static final String ID; }