@Test public void testSetPropertyActionFromAutomationQuery() throws Exception { DocumentModel model = session.getDocument(new PathRef("/default-domain/workspaces/test")); String nxql = String.format("SELECT * from ComplexDoc where ecm:parentId='%s'", model.getId()); String title = "test title"; String description = "test description"; String foo = "test foo"; String bar = "test bar"; HashMap<String, Serializable> complex = new HashMap<>(); complex.put("foo", foo); complex.put("bar", bar); Map<String, Serializable> params = new HashMap<>(); params.put("action", SetPropertiesAction.ACTION_NAME); params.put("query", nxql); HashMap<String, Serializable> actionParams = new HashMap<>(); actionParams.put("dc:title", title); actionParams.put("dc:description", description); actionParams.put("cpx:complex", complex); params.put("parameters", OBJECT_MAPPER.writeValueAsString(actionParams)); BulkStatus runResult = (BulkStatus) service.run(ctx, BulkRunAction.ID, params); assertNotNull(runResult); String commandId = runResult.getId(); boolean waitResult = (boolean) service.run(ctx, BulkWaitForAction.ID, singletonMap("commandId", commandId)); assertTrue("Bulk action didn't finish", waitResult); txFeature.nextTransaction(); for (DocumentModel child : session.query(nxql)) { assertEquals(title, child.getTitle()); assertEquals(description, child.getPropertyValue("dc:description")); assertEquals(foo, child.getPropertyValue("cpx:complex/foo")); assertEquals(bar, child.getPropertyValue("cpx:complex/bar")); } }
@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; }