@Test @RunWithCustomExecutor public void testDetachment() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(0); String containedId = GUIDFactory.newGUID().toString(); String unitId = GUIDFactory.newGUID().toString(); final WorkerParameters parameters = WorkerParametersFactory.newWorkerParameters().setWorkerGUID(GUIDFactory .newGUID().getId()).setContainerName(containedId) .setObjectNameList(Lists.newArrayList(unitId)) .setObjectName(unitId).setCurrentStep("StepName"); HandlerIO handlerIO = mock(HandlerIO.class); doReturn(JsonHandler.toJsonNode(new HashSet<>(Arrays.asList("parentId1", "parentId2")))) .when(handlerIO).getJsonFromWorkspace(eq(UNITS_TO_ATTACH_DIR + "/" + unitId)); unitAttachmentPlugin.execute(parameters, handlerIO); verify(metaDataClient).updateUnitById(any(), eq(unitId)); ArgumentCaptor<LogbookLifeCycleUnitParameters> logbookLCParam = ArgumentCaptor.forClass(LogbookLifeCycleUnitParameters.class); verify(logbookLifeCyclesClient).update(logbookLCParam.capture(), eq(LifeCycleStatusCode.LIFE_CYCLE_COMMITTED)); assertThat(logbookLCParam.getValue().getStatus()).isEqualTo(StatusCode.OK); String evDetData = logbookLCParam.getValue().getMapParameters().get(LogbookParameterName.eventDetailData); ReclassificationEventDetails eventDetails = JsonHandler.getFromString(evDetData, ReclassificationEventDetails.class); assertThat(eventDetails.getAddedParents()).containsExactlyInAnyOrder("parentId1", "parentId2"); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { String unitId = param.getObjectName(); try { Set<String> parentUnitsToAdd = getParentsToAdd(handler, unitId); updateUnit(unitId, parentUnitsToAdd); updateUnitLifeCycle(param, unitId, parentUnitsToAdd); } catch (ProcessingStatusException e) { LOGGER.error("Unit attachment failed with status [" + e.getStatusCode() + "]", e); return buildItemStatus(UNIT_ATTACHMENT, e.getStatusCode(), e.getEventDetails()); } LOGGER.debug("Unit attachment succeeded: " + unitId); return buildItemStatus(UNIT_ATTACHMENT, StatusCode.OK, null); }
UnitAttachmentPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { String unitId = param.getObjectName(); try { Set<String> parentUnitsToAdd = getParentsToAdd(handler, unitId); updateUnit(unitId, parentUnitsToAdd); updateUnitLifeCycle(param, unitId, parentUnitsToAdd); } catch (ProcessingStatusException e) { LOGGER.error("Unit attachment failed with status [" + e.getStatusCode() + "]", e); return buildItemStatus(UNIT_ATTACHMENT, e.getStatusCode(), e.getEventDetails()); } LOGGER.debug("Unit attachment succeeded: " + unitId); return buildItemStatus(UNIT_ATTACHMENT, StatusCode.OK, null); } }
UnitAttachmentPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { String unitId = param.getObjectName(); try { Set<String> parentUnitsToAdd = getParentsToAdd(handler, unitId); updateUnit(unitId, parentUnitsToAdd); updateUnitLifeCycle(param, unitId, parentUnitsToAdd); } catch (ProcessingStatusException e) { LOGGER.error("Unit attachment failed with status [" + e.getStatusCode() + "]", e); return buildItemStatus(UNIT_ATTACHMENT, e.getStatusCode(), e.getEventDetails()); } LOGGER.debug("Unit attachment succeeded: " + unitId); return buildItemStatus(UNIT_ATTACHMENT, StatusCode.OK, null); } UnitAttachmentPlugin(); @VisibleForTesting  UnitAttachmentPlugin(
        LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory, MetaDataClientFactory metaDataClientFactory); }
UnitAttachmentPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { String unitId = param.getObjectName(); try { Set<String> parentUnitsToAdd = getParentsToAdd(handler, unitId); updateUnit(unitId, parentUnitsToAdd); updateUnitLifeCycle(param, unitId, parentUnitsToAdd); } catch (ProcessingStatusException e) { LOGGER.error("Unit attachment failed with status [" + e.getStatusCode() + "]", e); return buildItemStatus(UNIT_ATTACHMENT, e.getStatusCode(), e.getEventDetails()); } LOGGER.debug("Unit attachment succeeded: " + unitId); return buildItemStatus(UNIT_ATTACHMENT, StatusCode.OK, null); } UnitAttachmentPlugin(); @VisibleForTesting  UnitAttachmentPlugin(
        LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory, MetaDataClientFactory metaDataClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); }
UnitAttachmentPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { String unitId = param.getObjectName(); try { Set<String> parentUnitsToAdd = getParentsToAdd(handler, unitId); updateUnit(unitId, parentUnitsToAdd); updateUnitLifeCycle(param, unitId, parentUnitsToAdd); } catch (ProcessingStatusException e) { LOGGER.error("Unit attachment failed with status [" + e.getStatusCode() + "]", e); return buildItemStatus(UNIT_ATTACHMENT, e.getStatusCode(), e.getEventDetails()); } LOGGER.debug("Unit attachment succeeded: " + unitId); return buildItemStatus(UNIT_ATTACHMENT, StatusCode.OK, null); } UnitAttachmentPlugin(); @VisibleForTesting  UnitAttachmentPlugin(
        LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory, MetaDataClientFactory metaDataClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler);  }