@Test public void givenStartDateAfterEndDateWhenExecuteThenReturnResponseKO() throws Exception { when(workspaceClient.getObject(any(), eq("Units/archiveUnit.json"))) .thenReturn(Response.status(Status.OK).entity(archiveUnitStartDateAfterEndDate).build()); final ItemStatus response = plugin.execute(params, action); assertEquals(response.getGlobalStatus(), StatusCode.KO); assertEquals(response.getGlobalOutcomeDetailSubcode(), CheckArchiveUnitSchemaActionPlugin.CONSISTENCY); }
@Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID); try { checkAUJsonAgainstSchema(handler, params, itemStatus); itemStatus.increment(StatusCode.OK); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit schema validation failed " + params.getObjectName(), e); switch (e.getErrorCode()) { case SCHEMA_VALIDATION_FAILURE: { itemStatus.setGlobalOutcomeDetailSubcode(INVALID_UNIT); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ONTOLOGY_VALIDATION_FAILURE: { itemStatus.setItemId(ONTOLOGY_VALIDATION); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } case INVALID_UNIT_DATE_FORMAT: { itemStatus.setGlobalOutcomeDetailSubcode(DATE_FORMAT); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(e.getMessage()); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case INVALID_START_END_DATE: { itemStatus.setGlobalOutcomeDetailSubcode(CONSISTENCY); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: case UNKNOWN_ARCHIVE_UNIT_PROFILE: case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } } catch (final ArchiveUnitContainSpecialCharactersException e) { itemStatus.setItemId(UNIT_SANITIZE); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (final Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(itemStatus.getItemId(), itemStatus); } }
CheckArchiveUnitSchemaActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID); try { checkAUJsonAgainstSchema(handler, params, itemStatus); itemStatus.increment(StatusCode.OK); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit schema validation failed " + params.getObjectName(), e); switch (e.getErrorCode()) { case SCHEMA_VALIDATION_FAILURE: { itemStatus.setGlobalOutcomeDetailSubcode(INVALID_UNIT); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ONTOLOGY_VALIDATION_FAILURE: { itemStatus.setItemId(ONTOLOGY_VALIDATION); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } case INVALID_UNIT_DATE_FORMAT: { itemStatus.setGlobalOutcomeDetailSubcode(DATE_FORMAT); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(e.getMessage()); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case INVALID_START_END_DATE: { itemStatus.setGlobalOutcomeDetailSubcode(CONSISTENCY); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: case UNKNOWN_ARCHIVE_UNIT_PROFILE: case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } } catch (final ArchiveUnitContainSpecialCharactersException e) { itemStatus.setItemId(UNIT_SANITIZE); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (final Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(itemStatus.getItemId(), itemStatus); } } }
CheckArchiveUnitSchemaActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID); try { checkAUJsonAgainstSchema(handler, params, itemStatus); itemStatus.increment(StatusCode.OK); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit schema validation failed " + params.getObjectName(), e); switch (e.getErrorCode()) { case SCHEMA_VALIDATION_FAILURE: { itemStatus.setGlobalOutcomeDetailSubcode(INVALID_UNIT); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ONTOLOGY_VALIDATION_FAILURE: { itemStatus.setItemId(ONTOLOGY_VALIDATION); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } case INVALID_UNIT_DATE_FORMAT: { itemStatus.setGlobalOutcomeDetailSubcode(DATE_FORMAT); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(e.getMessage()); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case INVALID_START_END_DATE: { itemStatus.setGlobalOutcomeDetailSubcode(CONSISTENCY); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: case UNKNOWN_ARCHIVE_UNIT_PROFILE: case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } } catch (final ArchiveUnitContainSpecialCharactersException e) { itemStatus.setItemId(UNIT_SANITIZE); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (final Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(itemStatus.getItemId(), itemStatus); } } CheckArchiveUnitSchemaActionPlugin(); @VisibleForTesting  CheckArchiveUnitSchemaActionPlugin(UnitValidator unitValidator); }
CheckArchiveUnitSchemaActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID); try { checkAUJsonAgainstSchema(handler, params, itemStatus); itemStatus.increment(StatusCode.OK); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit schema validation failed " + params.getObjectName(), e); switch (e.getErrorCode()) { case SCHEMA_VALIDATION_FAILURE: { itemStatus.setGlobalOutcomeDetailSubcode(INVALID_UNIT); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ONTOLOGY_VALIDATION_FAILURE: { itemStatus.setItemId(ONTOLOGY_VALIDATION); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } case INVALID_UNIT_DATE_FORMAT: { itemStatus.setGlobalOutcomeDetailSubcode(DATE_FORMAT); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(e.getMessage()); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case INVALID_START_END_DATE: { itemStatus.setGlobalOutcomeDetailSubcode(CONSISTENCY); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: case UNKNOWN_ARCHIVE_UNIT_PROFILE: case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } } catch (final ArchiveUnitContainSpecialCharactersException e) { itemStatus.setItemId(UNIT_SANITIZE); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (final Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(itemStatus.getItemId(), itemStatus); } } CheckArchiveUnitSchemaActionPlugin(); @VisibleForTesting  CheckArchiveUnitSchemaActionPlugin(UnitValidator unitValidator); @Override ItemStatus execute(WorkerParameters params, HandlerIO handler); }
CheckArchiveUnitSchemaActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID); try { checkAUJsonAgainstSchema(handler, params, itemStatus); itemStatus.increment(StatusCode.OK); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (MetadataValidationException e) { LOGGER.warn("Unit schema validation failed " + params.getObjectName(), e); switch (e.getErrorCode()) { case SCHEMA_VALIDATION_FAILURE: { itemStatus.setGlobalOutcomeDetailSubcode(INVALID_UNIT); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ONTOLOGY_VALIDATION_FAILURE: { itemStatus.setItemId(ONTOLOGY_VALIDATION); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } case INVALID_UNIT_DATE_FORMAT: { itemStatus.setGlobalOutcomeDetailSubcode(DATE_FORMAT); itemStatus.increment(StatusCode.KO); itemStatus.setEvDetailData(e.getMessage()); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case INVALID_START_END_DATE: { itemStatus.setGlobalOutcomeDetailSubcode(CONSISTENCY); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(itemStatus.getItemId()).setItemsStatus(itemStatus.getItemId(), itemStatus); } case ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE: case ARCHIVE_UNIT_PROFILE_SCHEMA_INACTIVE: case UNKNOWN_ARCHIVE_UNIT_PROFILE: case EMPTY_ARCHIVE_UNIT_PROFILE_SCHEMA: default: throw new IllegalStateException("Unexpected value: " + e.getErrorCode()); } } catch (final ArchiveUnitContainSpecialCharactersException e) { itemStatus.setItemId(UNIT_SANITIZE); itemStatus.increment(StatusCode.KO); final ObjectNode object = JsonHandler.createObjectNode(); object.put(SedaConstants.EV_DET_TECH_DATA, e.getMessage()); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(object)); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(CHECK_UNIT_SCHEMA_TASK_ID, itemStatus); } catch (final Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(CHECK_UNIT_SCHEMA_TASK_ID).setItemsStatus(itemStatus.getItemId(), itemStatus); } } CheckArchiveUnitSchemaActionPlugin(); @VisibleForTesting  CheckArchiveUnitSchemaActionPlugin(UnitValidator unitValidator); @Override ItemStatus execute(WorkerParameters params, HandlerIO handler);  }