@Test public void givenWorkspaceNotExistWhenExecuteThenReturnResponseFATAL() throws Exception { final List<ItemStatus> response = plugin.executeList(params, handlerIO); assertEquals(response.get(0).getGlobalStatus(), StatusCode.FATAL); }
@Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handlerIO) { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> itemStatuses = new ArrayList<>(); List<QueryCache> queryCaches = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handlerIO.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); QueryCache query = null; try { query = indexArchiveUnit(workerParameters, workerParameters.getContainerName(), workerParameters.getObjectName(), handlerIO); if (!query.update) { queryCaches.add(query); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } else { metadataClient.updateUnitById(((UpdateMultiQuery) query.requestMultiple).getFinalUpdate(), query.unitId); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } } catch (final IllegalArgumentException | InvalidCreateOperationException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (InvalidParseOperationException e) { itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); throw new IllegalArgumentException(e); } catch (final MetaDataNotFoundException e) { LOGGER.error("Unit references a non existing unit " + query.toString()); throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } } List<BulkUnitInsertEntry> entries = queryCaches.stream() .map(query -> query.requestMultiple) .map(query -> ((InsertMultiQuery) query)) .map(query -> new BulkUnitInsertEntry(query.getRoots(), query.getData())) .collect(Collectors.toList()); StatusCode statusCode; try { metadataClient.insertUnitBulk(new BulkUnitInsertRequest(entries)); statusCode = StatusCode.OK; } catch (final IllegalArgumentException e) { throw e; } catch (InvalidParseOperationException | MetaDataNotFoundException e) { throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); statusCode = StatusCode.FATAL; } if (statusCode == StatusCode.FATAL || statusCode == StatusCode.ALREADY_EXECUTED) { for (int i = 0; i < workerParameters.getObjectNameList().size(); i++) { final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); itemStatus.increment(statusCode); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.set(i, itemsStatus); } } return itemStatuses; } finally { handlerIO.setCurrentObjectId(null); } }
IndexUnitActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handlerIO) { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> itemStatuses = new ArrayList<>(); List<QueryCache> queryCaches = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handlerIO.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); QueryCache query = null; try { query = indexArchiveUnit(workerParameters, workerParameters.getContainerName(), workerParameters.getObjectName(), handlerIO); if (!query.update) { queryCaches.add(query); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } else { metadataClient.updateUnitById(((UpdateMultiQuery) query.requestMultiple).getFinalUpdate(), query.unitId); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } } catch (final IllegalArgumentException | InvalidCreateOperationException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (InvalidParseOperationException e) { itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); throw new IllegalArgumentException(e); } catch (final MetaDataNotFoundException e) { LOGGER.error("Unit references a non existing unit " + query.toString()); throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } } List<BulkUnitInsertEntry> entries = queryCaches.stream() .map(query -> query.requestMultiple) .map(query -> ((InsertMultiQuery) query)) .map(query -> new BulkUnitInsertEntry(query.getRoots(), query.getData())) .collect(Collectors.toList()); StatusCode statusCode; try { metadataClient.insertUnitBulk(new BulkUnitInsertRequest(entries)); statusCode = StatusCode.OK; } catch (final IllegalArgumentException e) { throw e; } catch (InvalidParseOperationException | MetaDataNotFoundException e) { throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); statusCode = StatusCode.FATAL; } if (statusCode == StatusCode.FATAL || statusCode == StatusCode.ALREADY_EXECUTED) { for (int i = 0; i < workerParameters.getObjectNameList().size(); i++) { final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); itemStatus.increment(statusCode); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.set(i, itemsStatus); } } return itemStatuses; } finally { handlerIO.setCurrentObjectId(null); } } }
IndexUnitActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handlerIO) { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> itemStatuses = new ArrayList<>(); List<QueryCache> queryCaches = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handlerIO.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); QueryCache query = null; try { query = indexArchiveUnit(workerParameters, workerParameters.getContainerName(), workerParameters.getObjectName(), handlerIO); if (!query.update) { queryCaches.add(query); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } else { metadataClient.updateUnitById(((UpdateMultiQuery) query.requestMultiple).getFinalUpdate(), query.unitId); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } } catch (final IllegalArgumentException | InvalidCreateOperationException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (InvalidParseOperationException e) { itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); throw new IllegalArgumentException(e); } catch (final MetaDataNotFoundException e) { LOGGER.error("Unit references a non existing unit " + query.toString()); throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } } List<BulkUnitInsertEntry> entries = queryCaches.stream() .map(query -> query.requestMultiple) .map(query -> ((InsertMultiQuery) query)) .map(query -> new BulkUnitInsertEntry(query.getRoots(), query.getData())) .collect(Collectors.toList()); StatusCode statusCode; try { metadataClient.insertUnitBulk(new BulkUnitInsertRequest(entries)); statusCode = StatusCode.OK; } catch (final IllegalArgumentException e) { throw e; } catch (InvalidParseOperationException | MetaDataNotFoundException e) { throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); statusCode = StatusCode.FATAL; } if (statusCode == StatusCode.FATAL || statusCode == StatusCode.ALREADY_EXECUTED) { for (int i = 0; i < workerParameters.getObjectNameList().size(); i++) { final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); itemStatus.increment(statusCode); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.set(i, itemsStatus); } } return itemStatuses; } finally { handlerIO.setCurrentObjectId(null); } } IndexUnitActionPlugin(); @VisibleForTesting  IndexUnitActionPlugin(MetaDataClientFactory metaDataClientFactory); }
IndexUnitActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handlerIO) { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> itemStatuses = new ArrayList<>(); List<QueryCache> queryCaches = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handlerIO.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); QueryCache query = null; try { query = indexArchiveUnit(workerParameters, workerParameters.getContainerName(), workerParameters.getObjectName(), handlerIO); if (!query.update) { queryCaches.add(query); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } else { metadataClient.updateUnitById(((UpdateMultiQuery) query.requestMultiple).getFinalUpdate(), query.unitId); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } } catch (final IllegalArgumentException | InvalidCreateOperationException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (InvalidParseOperationException e) { itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); throw new IllegalArgumentException(e); } catch (final MetaDataNotFoundException e) { LOGGER.error("Unit references a non existing unit " + query.toString()); throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } } List<BulkUnitInsertEntry> entries = queryCaches.stream() .map(query -> query.requestMultiple) .map(query -> ((InsertMultiQuery) query)) .map(query -> new BulkUnitInsertEntry(query.getRoots(), query.getData())) .collect(Collectors.toList()); StatusCode statusCode; try { metadataClient.insertUnitBulk(new BulkUnitInsertRequest(entries)); statusCode = StatusCode.OK; } catch (final IllegalArgumentException e) { throw e; } catch (InvalidParseOperationException | MetaDataNotFoundException e) { throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); statusCode = StatusCode.FATAL; } if (statusCode == StatusCode.FATAL || statusCode == StatusCode.ALREADY_EXECUTED) { for (int i = 0; i < workerParameters.getObjectNameList().size(); i++) { final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); itemStatus.increment(statusCode); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.set(i, itemsStatus); } } return itemStatuses; } finally { handlerIO.setCurrentObjectId(null); } } IndexUnitActionPlugin(); @VisibleForTesting  IndexUnitActionPlugin(MetaDataClientFactory metaDataClientFactory); static String getId(); @Override ItemStatus execute(WorkerParameters params, HandlerIO param); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handlerIO); @Override void checkMandatoryIOParameter(HandlerIO handler); }
IndexUnitActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handlerIO) { try (MetaDataClient metadataClient = metaDataClientFactory.getClient()) { List<ItemStatus> itemStatuses = new ArrayList<>(); List<QueryCache> queryCaches = new ArrayList<>(); for (String objectId : workerParameters.getObjectNameList()) { workerParameters.setObjectName(objectId); handlerIO.setCurrentObjectId(objectId); checkMandatoryParameters(workerParameters); final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); QueryCache query = null; try { query = indexArchiveUnit(workerParameters, workerParameters.getContainerName(), workerParameters.getObjectName(), handlerIO); if (!query.update) { queryCaches.add(query); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } else { metadataClient.updateUnitById(((UpdateMultiQuery) query.requestMultiple).getFinalUpdate(), query.unitId); itemStatus.increment(StatusCode.OK); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } } catch (final IllegalArgumentException | InvalidCreateOperationException e) { LOGGER.error(e); itemStatus.increment(StatusCode.KO); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (final ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); } catch (InvalidParseOperationException e) { itemStatus.increment(StatusCode.FATAL); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.add(itemsStatus); throw new IllegalArgumentException(e); } catch (final MetaDataNotFoundException e) { LOGGER.error("Unit references a non existing unit " + query.toString()); throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } } List<BulkUnitInsertEntry> entries = queryCaches.stream() .map(query -> query.requestMultiple) .map(query -> ((InsertMultiQuery) query)) .map(query -> new BulkUnitInsertEntry(query.getRoots(), query.getData())) .collect(Collectors.toList()); StatusCode statusCode; try { metadataClient.insertUnitBulk(new BulkUnitInsertRequest(entries)); statusCode = StatusCode.OK; } catch (final IllegalArgumentException e) { throw e; } catch (InvalidParseOperationException | MetaDataNotFoundException e) { throw new IllegalArgumentException(e); } catch (final MetaDataException e) { LOGGER.error(e); statusCode = StatusCode.FATAL; } if (statusCode == StatusCode.FATAL || statusCode == StatusCode.ALREADY_EXECUTED) { for (int i = 0; i < workerParameters.getObjectNameList().size(); i++) { final ItemStatus itemStatus = new ItemStatus(HANDLER_PROCESS); itemStatus.increment(statusCode); ItemStatus itemsStatus = new ItemStatus(HANDLER_PROCESS).setItemsStatus(HANDLER_PROCESS, itemStatus); itemStatuses.set(i, itemsStatus); } } return itemStatuses; } finally { handlerIO.setCurrentObjectId(null); } } IndexUnitActionPlugin(); @VisibleForTesting  IndexUnitActionPlugin(MetaDataClientFactory metaDataClientFactory); static String getId(); @Override ItemStatus execute(WorkerParameters params, HandlerIO param); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handlerIO); @Override void checkMandatoryIOParameter(HandlerIO handler);  }