@Test public void givenMetadataBadRequestWhenExecuteOnExistingGotThenReturnResponseKO() throws Exception { ObjectNode existingOgRaw = (ObjectNode) existingOg.deepCopy(); existingOgRaw.remove("_work"); doThrow(new InvalidParseOperationException("")).when(metadataClient).updateObjectGroupById(any(), any()); when(metadataClient.getObjectGroupByIdRaw(any())).thenReturn(new RequestResponseOK<JsonNode>().addResult(existingOgRaw)); handlerIO.getInput().clear(); handlerIO.getInput().add(existingOg); plugin = new IndexObjectGroupActionPlugin(metaDataClientFactory); final WorkerParameters params = WorkerParametersFactory.newWorkerParameters().setUrlWorkspace("http: .setUrlMetadata("http: .setObjectNameList(Lists.newArrayList("objectName.json")) .setObjectName("objectName.json").setCurrentStep("currentStep") .setContainerName("IndexObjectGroupActionPluginTest"); final ItemStatus response = plugin.executeList(params, handlerIO).get(0); assertEquals(StatusCode.KO, response.getGlobalStatus()); }
@Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> aggregateItemStatus = new ArrayList<>(); List<JsonNode> objectGroups = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handler.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(OG_INDEXATION); try { checkMandatoryIOParameter(handler); JsonNode objectNode = indexObjectGroup(handler, workerParameters, itemStatus); if (objectNode != null) { objectGroups.add(objectNode); } } catch (final StepAlreadyExecutedException e) { LOGGER.warn(e); itemStatus.increment(StatusCode.ALREADY_EXECUTED); } catch (final ProcessingInternalServerException exc) { LOGGER.error(exc); itemStatus.increment(StatusCode.FATAL); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); } if (StatusCode.UNKNOWN.equals(itemStatus.getGlobalStatus())) { itemStatus.increment(StatusCode.WARNING); } aggregateItemStatus.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, itemStatus)); } if (!objectGroups.isEmpty()) { try { metadataClient.insertObjectGroups(objectGroups); } catch (final MetaDataException | InvalidParseOperationException e) { LOGGER.error(e); List<ItemStatus> aggregateItemStatusBis = new ArrayList<>(); for (ItemStatus ignored : aggregateItemStatus) { aggregateItemStatusBis.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, new ItemStatus(OG_INDEXATION).increment(StatusCode.FATAL))); } aggregateItemStatus = aggregateItemStatusBis; } } return aggregateItemStatus; } finally { handler.setCurrentObjectId(null); } }
IndexObjectGroupActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> aggregateItemStatus = new ArrayList<>(); List<JsonNode> objectGroups = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handler.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(OG_INDEXATION); try { checkMandatoryIOParameter(handler); JsonNode objectNode = indexObjectGroup(handler, workerParameters, itemStatus); if (objectNode != null) { objectGroups.add(objectNode); } } catch (final StepAlreadyExecutedException e) { LOGGER.warn(e); itemStatus.increment(StatusCode.ALREADY_EXECUTED); } catch (final ProcessingInternalServerException exc) { LOGGER.error(exc); itemStatus.increment(StatusCode.FATAL); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); } if (StatusCode.UNKNOWN.equals(itemStatus.getGlobalStatus())) { itemStatus.increment(StatusCode.WARNING); } aggregateItemStatus.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, itemStatus)); } if (!objectGroups.isEmpty()) { try { metadataClient.insertObjectGroups(objectGroups); } catch (final MetaDataException | InvalidParseOperationException e) { LOGGER.error(e); List<ItemStatus> aggregateItemStatusBis = new ArrayList<>(); for (ItemStatus ignored : aggregateItemStatus) { aggregateItemStatusBis.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, new ItemStatus(OG_INDEXATION).increment(StatusCode.FATAL))); } aggregateItemStatus = aggregateItemStatusBis; } } return aggregateItemStatus; } finally { handler.setCurrentObjectId(null); } } }
IndexObjectGroupActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> aggregateItemStatus = new ArrayList<>(); List<JsonNode> objectGroups = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handler.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(OG_INDEXATION); try { checkMandatoryIOParameter(handler); JsonNode objectNode = indexObjectGroup(handler, workerParameters, itemStatus); if (objectNode != null) { objectGroups.add(objectNode); } } catch (final StepAlreadyExecutedException e) { LOGGER.warn(e); itemStatus.increment(StatusCode.ALREADY_EXECUTED); } catch (final ProcessingInternalServerException exc) { LOGGER.error(exc); itemStatus.increment(StatusCode.FATAL); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); } if (StatusCode.UNKNOWN.equals(itemStatus.getGlobalStatus())) { itemStatus.increment(StatusCode.WARNING); } aggregateItemStatus.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, itemStatus)); } if (!objectGroups.isEmpty()) { try { metadataClient.insertObjectGroups(objectGroups); } catch (final MetaDataException | InvalidParseOperationException e) { LOGGER.error(e); List<ItemStatus> aggregateItemStatusBis = new ArrayList<>(); for (ItemStatus ignored : aggregateItemStatus) { aggregateItemStatusBis.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, new ItemStatus(OG_INDEXATION).increment(StatusCode.FATAL))); } aggregateItemStatus = aggregateItemStatusBis; } } return aggregateItemStatus; } finally { handler.setCurrentObjectId(null); } } IndexObjectGroupActionPlugin(); @VisibleForTesting  IndexObjectGroupActionPlugin(MetaDataClientFactory metaDataClientFactory); }
IndexObjectGroupActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> aggregateItemStatus = new ArrayList<>(); List<JsonNode> objectGroups = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handler.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(OG_INDEXATION); try { checkMandatoryIOParameter(handler); JsonNode objectNode = indexObjectGroup(handler, workerParameters, itemStatus); if (objectNode != null) { objectGroups.add(objectNode); } } catch (final StepAlreadyExecutedException e) { LOGGER.warn(e); itemStatus.increment(StatusCode.ALREADY_EXECUTED); } catch (final ProcessingInternalServerException exc) { LOGGER.error(exc); itemStatus.increment(StatusCode.FATAL); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); } if (StatusCode.UNKNOWN.equals(itemStatus.getGlobalStatus())) { itemStatus.increment(StatusCode.WARNING); } aggregateItemStatus.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, itemStatus)); } if (!objectGroups.isEmpty()) { try { metadataClient.insertObjectGroups(objectGroups); } catch (final MetaDataException | InvalidParseOperationException e) { LOGGER.error(e); List<ItemStatus> aggregateItemStatusBis = new ArrayList<>(); for (ItemStatus ignored : aggregateItemStatus) { aggregateItemStatusBis.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, new ItemStatus(OG_INDEXATION).increment(StatusCode.FATAL))); } aggregateItemStatus = aggregateItemStatusBis; } } return aggregateItemStatus; } finally { handler.setCurrentObjectId(null); } } IndexObjectGroupActionPlugin(); @VisibleForTesting  IndexObjectGroupActionPlugin(MetaDataClientFactory metaDataClientFactory); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler); @Override ItemStatus execute(WorkerParameters params, HandlerIO param); @Override void checkMandatoryIOParameter(HandlerIO handler); }
IndexObjectGroupActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> aggregateItemStatus = new ArrayList<>(); List<JsonNode> objectGroups = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handler.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(OG_INDEXATION); try { checkMandatoryIOParameter(handler); JsonNode objectNode = indexObjectGroup(handler, workerParameters, itemStatus); if (objectNode != null) { objectGroups.add(objectNode); } } catch (final StepAlreadyExecutedException e) { LOGGER.warn(e); itemStatus.increment(StatusCode.ALREADY_EXECUTED); } catch (final ProcessingInternalServerException exc) { LOGGER.error(exc); itemStatus.increment(StatusCode.FATAL); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); } if (StatusCode.UNKNOWN.equals(itemStatus.getGlobalStatus())) { itemStatus.increment(StatusCode.WARNING); } aggregateItemStatus.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, itemStatus)); } if (!objectGroups.isEmpty()) { try { metadataClient.insertObjectGroups(objectGroups); } catch (final MetaDataException | InvalidParseOperationException e) { LOGGER.error(e); List<ItemStatus> aggregateItemStatusBis = new ArrayList<>(); for (ItemStatus ignored : aggregateItemStatus) { aggregateItemStatusBis.add(new ItemStatus(OG_INDEXATION).setItemsStatus(OG_INDEXATION, new ItemStatus(OG_INDEXATION).increment(StatusCode.FATAL))); } aggregateItemStatus = aggregateItemStatusBis; } } return aggregateItemStatus; } finally { handler.setCurrentObjectId(null); } } IndexObjectGroupActionPlugin(); @VisibleForTesting  IndexObjectGroupActionPlugin(MetaDataClientFactory metaDataClientFactory); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler); @Override ItemStatus execute(WorkerParameters params, HandlerIO param); @Override void checkMandatoryIOParameter(HandlerIO handler);  }