@Test public void givenWorkspaceNotExistWhenExecuteThenReturnResponseFATAL() throws ProcessingException { final ItemStatus response = plugin.execute(params, handlerIO); assertEquals(response.getGlobalStatus(), StatusCode.FATAL); }
@Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { checkMandatoryParameters(params); final String objectName = params.getObjectName(); final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID); ObjectNode infoNode = JsonHandler.createObjectNode(); String unitId = ""; String url = ARCHIVE_UNIT_FOLDER + separator + objectName; try (InputStream archiveUnitInputStream = handlerIO.getInputStreamFromWorkspace(url)) { ObjectNode archiveUnit = (ObjectNode) JsonHandler.getFromInputStream(archiveUnitInputStream); JsonNode archiveUnitTag = archiveUnit.get(TAG_ARCHIVE_UNIT); boolean hasArchiveUnitProfile = archiveUnitTag.has(TAG_ARCHIVE_UNIT_PROFILE); if (!hasArchiveUnitProfile) { String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } final File file = (File) handlerIO.getInput(GUID_MAP_RANK); String archiveUnitTagId = archiveUnitTag.get(PREFIX_ID).asText(); if (file != null) { JsonNode fromFile = JsonHandler.getFromFile(file); unitId = fromFile.path(archiveUnitTagId).asText(); } String archiveUnitProfileIdentifier = archiveUnitTag.get(TAG_ARCHIVE_UNIT_PROFILE).asText(); try { PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); LOGGER.info("START - Validation of archive unit {} on {} - Time: {}", archiveUnitTagId, archiveUnitProfileIdentifier, Instant.now().toEpochMilli()); checkAUAgainstAUProfileSchema(archiveUnit); PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit archive unit profile validation failed " + params.getObjectName(), e); String outcomeDetails; switch (e.getErrorCode()) { case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: outcomeDetails = OUTCOME_DETAILS_NOT_AU_JSON_VALID; break; case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: outcomeDetails = OUTCOME_DETAILS_EMPTY_CONTROL_SCHEMA; break; case UNKNOWN_ARCHIVE_UNIT_PROFILE: outcomeDetails = OUTCOME_DETAILS_NOT_FOUND; break; case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: outcomeDetails = OUTCOME_DETAILS_INACTIVE_STATUS; break; case ONTOLOGY_VALIDATION_FAILURE: case INVALID_UNIT_DATE_FORMAT: case INVALID_START_END_DATE: case SCHEMA_VALIDATION_FAILURE: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } infoNode.put(TAG_ARCHIVE_UNIT, unitId) .put(TAG_ARCHIVE_UNIT_PROFILE, archiveUnitProfileIdentifier) .put(EV_DET_TECH_DATA, e.getMessage()); return createItemStatusKo(itemStatus, outcomeDetails, infoNode); } } catch (Exception e) { LOGGER.error(e); itemStatus.increment(FATAL); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID).setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } }
CheckArchiveUnitProfileActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { checkMandatoryParameters(params); final String objectName = params.getObjectName(); final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID); ObjectNode infoNode = JsonHandler.createObjectNode(); String unitId = ""; String url = ARCHIVE_UNIT_FOLDER + separator + objectName; try (InputStream archiveUnitInputStream = handlerIO.getInputStreamFromWorkspace(url)) { ObjectNode archiveUnit = (ObjectNode) JsonHandler.getFromInputStream(archiveUnitInputStream); JsonNode archiveUnitTag = archiveUnit.get(TAG_ARCHIVE_UNIT); boolean hasArchiveUnitProfile = archiveUnitTag.has(TAG_ARCHIVE_UNIT_PROFILE); if (!hasArchiveUnitProfile) { String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } final File file = (File) handlerIO.getInput(GUID_MAP_RANK); String archiveUnitTagId = archiveUnitTag.get(PREFIX_ID).asText(); if (file != null) { JsonNode fromFile = JsonHandler.getFromFile(file); unitId = fromFile.path(archiveUnitTagId).asText(); } String archiveUnitProfileIdentifier = archiveUnitTag.get(TAG_ARCHIVE_UNIT_PROFILE).asText(); try { PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); LOGGER.info("START - Validation of archive unit {} on {} - Time: {}", archiveUnitTagId, archiveUnitProfileIdentifier, Instant.now().toEpochMilli()); checkAUAgainstAUProfileSchema(archiveUnit); PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit archive unit profile validation failed " + params.getObjectName(), e); String outcomeDetails; switch (e.getErrorCode()) { case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: outcomeDetails = OUTCOME_DETAILS_NOT_AU_JSON_VALID; break; case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: outcomeDetails = OUTCOME_DETAILS_EMPTY_CONTROL_SCHEMA; break; case UNKNOWN_ARCHIVE_UNIT_PROFILE: outcomeDetails = OUTCOME_DETAILS_NOT_FOUND; break; case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: outcomeDetails = OUTCOME_DETAILS_INACTIVE_STATUS; break; case ONTOLOGY_VALIDATION_FAILURE: case INVALID_UNIT_DATE_FORMAT: case INVALID_START_END_DATE: case SCHEMA_VALIDATION_FAILURE: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } infoNode.put(TAG_ARCHIVE_UNIT, unitId) .put(TAG_ARCHIVE_UNIT_PROFILE, archiveUnitProfileIdentifier) .put(EV_DET_TECH_DATA, e.getMessage()); return createItemStatusKo(itemStatus, outcomeDetails, infoNode); } } catch (Exception e) { LOGGER.error(e); itemStatus.increment(FATAL); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID).setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } } }
CheckArchiveUnitProfileActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { checkMandatoryParameters(params); final String objectName = params.getObjectName(); final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID); ObjectNode infoNode = JsonHandler.createObjectNode(); String unitId = ""; String url = ARCHIVE_UNIT_FOLDER + separator + objectName; try (InputStream archiveUnitInputStream = handlerIO.getInputStreamFromWorkspace(url)) { ObjectNode archiveUnit = (ObjectNode) JsonHandler.getFromInputStream(archiveUnitInputStream); JsonNode archiveUnitTag = archiveUnit.get(TAG_ARCHIVE_UNIT); boolean hasArchiveUnitProfile = archiveUnitTag.has(TAG_ARCHIVE_UNIT_PROFILE); if (!hasArchiveUnitProfile) { String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } final File file = (File) handlerIO.getInput(GUID_MAP_RANK); String archiveUnitTagId = archiveUnitTag.get(PREFIX_ID).asText(); if (file != null) { JsonNode fromFile = JsonHandler.getFromFile(file); unitId = fromFile.path(archiveUnitTagId).asText(); } String archiveUnitProfileIdentifier = archiveUnitTag.get(TAG_ARCHIVE_UNIT_PROFILE).asText(); try { PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); LOGGER.info("START - Validation of archive unit {} on {} - Time: {}", archiveUnitTagId, archiveUnitProfileIdentifier, Instant.now().toEpochMilli()); checkAUAgainstAUProfileSchema(archiveUnit); PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit archive unit profile validation failed " + params.getObjectName(), e); String outcomeDetails; switch (e.getErrorCode()) { case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: outcomeDetails = OUTCOME_DETAILS_NOT_AU_JSON_VALID; break; case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: outcomeDetails = OUTCOME_DETAILS_EMPTY_CONTROL_SCHEMA; break; case UNKNOWN_ARCHIVE_UNIT_PROFILE: outcomeDetails = OUTCOME_DETAILS_NOT_FOUND; break; case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: outcomeDetails = OUTCOME_DETAILS_INACTIVE_STATUS; break; case ONTOLOGY_VALIDATION_FAILURE: case INVALID_UNIT_DATE_FORMAT: case INVALID_START_END_DATE: case SCHEMA_VALIDATION_FAILURE: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } infoNode.put(TAG_ARCHIVE_UNIT, unitId) .put(TAG_ARCHIVE_UNIT_PROFILE, archiveUnitProfileIdentifier) .put(EV_DET_TECH_DATA, e.getMessage()); return createItemStatusKo(itemStatus, outcomeDetails, infoNode); } } catch (Exception e) { LOGGER.error(e); itemStatus.increment(FATAL); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID).setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } } CheckArchiveUnitProfileActionPlugin(); @VisibleForTesting  CheckArchiveUnitProfileActionPlugin(UnitValidator unitValidator); }
CheckArchiveUnitProfileActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { checkMandatoryParameters(params); final String objectName = params.getObjectName(); final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID); ObjectNode infoNode = JsonHandler.createObjectNode(); String unitId = ""; String url = ARCHIVE_UNIT_FOLDER + separator + objectName; try (InputStream archiveUnitInputStream = handlerIO.getInputStreamFromWorkspace(url)) { ObjectNode archiveUnit = (ObjectNode) JsonHandler.getFromInputStream(archiveUnitInputStream); JsonNode archiveUnitTag = archiveUnit.get(TAG_ARCHIVE_UNIT); boolean hasArchiveUnitProfile = archiveUnitTag.has(TAG_ARCHIVE_UNIT_PROFILE); if (!hasArchiveUnitProfile) { String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } final File file = (File) handlerIO.getInput(GUID_MAP_RANK); String archiveUnitTagId = archiveUnitTag.get(PREFIX_ID).asText(); if (file != null) { JsonNode fromFile = JsonHandler.getFromFile(file); unitId = fromFile.path(archiveUnitTagId).asText(); } String archiveUnitProfileIdentifier = archiveUnitTag.get(TAG_ARCHIVE_UNIT_PROFILE).asText(); try { PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); LOGGER.info("START - Validation of archive unit {} on {} - Time: {}", archiveUnitTagId, archiveUnitProfileIdentifier, Instant.now().toEpochMilli()); checkAUAgainstAUProfileSchema(archiveUnit); PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit archive unit profile validation failed " + params.getObjectName(), e); String outcomeDetails; switch (e.getErrorCode()) { case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: outcomeDetails = OUTCOME_DETAILS_NOT_AU_JSON_VALID; break; case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: outcomeDetails = OUTCOME_DETAILS_EMPTY_CONTROL_SCHEMA; break; case UNKNOWN_ARCHIVE_UNIT_PROFILE: outcomeDetails = OUTCOME_DETAILS_NOT_FOUND; break; case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: outcomeDetails = OUTCOME_DETAILS_INACTIVE_STATUS; break; case ONTOLOGY_VALIDATION_FAILURE: case INVALID_UNIT_DATE_FORMAT: case INVALID_START_END_DATE: case SCHEMA_VALIDATION_FAILURE: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } infoNode.put(TAG_ARCHIVE_UNIT, unitId) .put(TAG_ARCHIVE_UNIT_PROFILE, archiveUnitProfileIdentifier) .put(EV_DET_TECH_DATA, e.getMessage()); return createItemStatusKo(itemStatus, outcomeDetails, infoNode); } } catch (Exception e) { LOGGER.error(e); itemStatus.increment(FATAL); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID).setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } } CheckArchiveUnitProfileActionPlugin(); @VisibleForTesting  CheckArchiveUnitProfileActionPlugin(UnitValidator unitValidator); @Override ItemStatus execute(WorkerParameters params, HandlerIO handlerIO); }
CheckArchiveUnitProfileActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { checkMandatoryParameters(params); final String objectName = params.getObjectName(); final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID); ObjectNode infoNode = JsonHandler.createObjectNode(); String unitId = ""; String url = ARCHIVE_UNIT_FOLDER + separator + objectName; try (InputStream archiveUnitInputStream = handlerIO.getInputStreamFromWorkspace(url)) { ObjectNode archiveUnit = (ObjectNode) JsonHandler.getFromInputStream(archiveUnitInputStream); JsonNode archiveUnitTag = archiveUnit.get(TAG_ARCHIVE_UNIT); boolean hasArchiveUnitProfile = archiveUnitTag.has(TAG_ARCHIVE_UNIT_PROFILE); if (!hasArchiveUnitProfile) { String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } final File file = (File) handlerIO.getInput(GUID_MAP_RANK); String archiveUnitTagId = archiveUnitTag.get(PREFIX_ID).asText(); if (file != null) { JsonNode fromFile = JsonHandler.getFromFile(file); unitId = fromFile.path(archiveUnitTagId).asText(); } String archiveUnitProfileIdentifier = archiveUnitTag.get(TAG_ARCHIVE_UNIT_PROFILE).asText(); try { PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); LOGGER.info("START - Validation of archive unit {} on {} - Time: {}", archiveUnitTagId, archiveUnitProfileIdentifier, Instant.now().toEpochMilli()); checkAUAgainstAUProfileSchema(archiveUnit); PerformanceLogger.getInstance().log(CHECK_UNIT_PROFILE_TASK_ID, "Validation of archive against AUP.", Instant.now().toEpochMilli()); String evdev = JsonHandler.unprettyPrint(infoNode); itemStatus.setEvDetailData(evdev) .setMasterData(eventDetailData.name(), evdev) .increment(OK); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID) .setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit archive unit profile validation failed " + params.getObjectName(), e); String outcomeDetails; switch (e.getErrorCode()) { case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: outcomeDetails = OUTCOME_DETAILS_NOT_AU_JSON_VALID; break; case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: outcomeDetails = OUTCOME_DETAILS_EMPTY_CONTROL_SCHEMA; break; case UNKNOWN_ARCHIVE_UNIT_PROFILE: outcomeDetails = OUTCOME_DETAILS_NOT_FOUND; break; case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: outcomeDetails = OUTCOME_DETAILS_INACTIVE_STATUS; break; case ONTOLOGY_VALIDATION_FAILURE: case INVALID_UNIT_DATE_FORMAT: case INVALID_START_END_DATE: case SCHEMA_VALIDATION_FAILURE: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } infoNode.put(TAG_ARCHIVE_UNIT, unitId) .put(TAG_ARCHIVE_UNIT_PROFILE, archiveUnitProfileIdentifier) .put(EV_DET_TECH_DATA, e.getMessage()); return createItemStatusKo(itemStatus, outcomeDetails, infoNode); } } catch (Exception e) { LOGGER.error(e); itemStatus.increment(FATAL); return new ItemStatus(CHECK_UNIT_PROFILE_TASK_ID).setItemsStatus(CHECK_UNIT_PROFILE_TASK_ID, itemStatus); } } CheckArchiveUnitProfileActionPlugin(); @VisibleForTesting  CheckArchiveUnitProfileActionPlugin(UnitValidator unitValidator); @Override ItemStatus execute(WorkerParameters params, HandlerIO handlerIO);  }