@Test(expected = MetaDataNotFoundException.class) @RunWithCustomExecutor public void given_test_updateUnitById_withWrongGUID() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); accessModuleImpl.updateUnitById(fromStringToJson(QUERY), "dfsdfsdf", REQUEST_ID); }
@Override public JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId) throws MetaDataNotFoundException, IllegalArgumentException, InvalidParseOperationException, AccessInternalExecutionException, UpdatePermissionException, AccessInternalRuleExecutionException { LogbookOperationParameters logbookOpStpParamStart; LogbookLifeCycleUnitParameters logbookLCParamEnd; ParametersChecker.checkParameter(ID_CHECK_FAILED, idUnit); JsonNode jsonNode = JsonHandler.createObjectNode(); boolean globalStep = true; boolean stepCheckPermission = true; boolean stepCheckRules = true; boolean stepMetadataUpdate = true; boolean stepStorageUpdate = true; boolean stepLFCCommit = true; final GUID idGUID; final GUID idRequest; try { idGUID = GUIDReader.getGUID(idUnit); idRequest = GUIDReader.getGUID(requestId); } catch (final InvalidGuidOperationException e) { LOGGER.error("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); throw new MetaDataNotFoundException("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); } final RequestParserMultiple parser = RequestParserHelper.getParser(queryJson); if (!(parser instanceof UpdateParserMultiple)) { parser.getRequest().reset(); throw new IllegalArgumentException("Request is not an update operation"); } final GUID updateOpGuidStart = idRequest; Boolean requestUpdateManagment = updateContainsManagmentFields(queryJson); String masterStpOperation = requestUpdateManagment ? STP_UPDATE_UNIT : STP_UPDATE_UNIT_DESC; try (MetaDataClient metaDataClient = metaDataClientFactory.getClient(); LogbookOperationsClient logbookOperationClient = logbookOperationsClientFactory.getClient(); LogbookLifeCyclesClient logbookLifeCycleClient = logbookLifeCyclesClientFactory.getClient()) { logbookOpStpParamStart = getLogbookOperationUpdateUnitParameters(updateOpGuidStart, updateOpGuidStart, StatusCode.STARTED, VitamLogbookMessages.getCodeOp(masterStpOperation, StatusCode.STARTED), idRequest, masterStpOperation, true); logbookOpStpParamStart.putParameterValue(LogbookParameterName.objectIdentifier, idUnit); logbookOpStpParamStart.putParameterValue(LogbookParameterName.outcomeDetail, STP_UPDATE_UNIT + "." + StatusCode.STARTED); logbookOperationClient.create(logbookOpStpParamStart); globalStep = false; stepCheckPermission = false; checkPermissions(requestUpdateManagment); stepCheckPermission = true; if (requestUpdateManagment) { stepCheckRules = false; checkAndUpdateRuleQuery((UpdateParserMultiple) parser); stepCheckRules = true; } try { queryJson = ((UpdateParserMultiple) parser).getRequest() .addActions(UpdateActionHelper.push(VitamFieldsHelper.operations(), updateOpGuidStart.toString())) .getFinalUpdate(); } catch (final InvalidCreateOperationException e) { LOGGER.error(e); throw new AccessInternalExecutionException(ERROR_ADD_CONDITION, e); } stepMetadataUpdate = false; jsonNode = metaDataClient.updateUnitById(queryJson, idUnit); stepMetadataUpdate = true; logbookLCParamEnd = getLogbookLifeCycleUpdateUnitParameters(updateOpGuidStart, StatusCode.OK, idGUID, UNIT_METADATA_UPDATE); logbookLCParamEnd.putParameterValue(LogbookParameterName.eventDetailData, getDiffMessageFor(jsonNode, idUnit)); stepLFCCommit = false; logbookLifeCycleClient.update(logbookLCParamEnd, LifeCycleStatusCode.LIFE_CYCLE_COMMITTED); stepLFCCommit = true; stepStorageUpdate = false; replaceStoredUnitMetadata(idUnit, requestId); stepStorageUpdate = true; globalStep = true; finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (final InvalidParseOperationException ipoe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, ipoe.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(PARSING_ERROR, ipoe); throw ipoe; } catch (final IllegalArgumentException iae) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(ILLEGAL_ARGUMENT, iae); throw iae; } catch (final MetaDataNotFoundException mdnfe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, DT_NO_EXTISTING); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_NOT_FOUND_ERROR, mdnfe); throw mdnfe; } catch (final MetaDataDocumentSizeException mddse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_DOCUMENT_SIZE_ERROR, mddse); throw new AccessInternalExecutionException(mddse); } catch (final LogbookClientServerException lcse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(DOCUMENT_CLIENT_SERVER_ERROR, lcse); throw new AccessInternalExecutionException(lcse); } catch (final MetaDataExecutionException mdee) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_EXECUTION_EXECUTION_ERROR, mdee); throw new AccessInternalExecutionException(mdee); } catch (final LogbookClientNotFoundException lcnfe) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_NOT_FOUND_ERROR, lcnfe); throw new AccessInternalExecutionException(lcnfe); } catch (final LogbookClientBadRequestException lcbre) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_BAD_REQUEST_ERROR, lcbre); throw new AccessInternalExecutionException(lcbre); } catch (final LogbookClientAlreadyExistsException e) { LOGGER.error(LOGBOOK_OPERATION_ALREADY_EXISTS, e); throw new AccessInternalExecutionException(e); } catch (final MetaDataClientServerException e) { LOGGER.error(METADATA_INTERNAL_SERVER_ERROR, e); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); throw new AccessInternalExecutionException(e); } catch (StorageClientException e) { try { finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (LogbookClientBadRequestException | LogbookClientNotFoundException | LogbookClientServerException e1) { LOGGER.error(STORAGE_SERVER_EXCEPTION, e1); } LOGGER.error(STORAGE_SERVER_EXCEPTION, e); throw new AccessInternalExecutionException(STORAGE_SERVER_EXCEPTION, e); } catch (ContentAddressableStorageException e) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(WORKSPACE_SERVER_EXCEPTION, e); } catch (AccessInternalRuleExecutionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_RULES, e); throw e; } catch (final UpdatePermissionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_PERMISSIONS, e); throw e; } catch (AccessInternalException e) { LOGGER.error(ARCHIVE_UNIT_NOT_FOUND, e); throw new AccessInternalExecutionException(e); } return jsonNode; }
AccessInternalModuleImpl implements AccessInternalModule { @Override public JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId) throws MetaDataNotFoundException, IllegalArgumentException, InvalidParseOperationException, AccessInternalExecutionException, UpdatePermissionException, AccessInternalRuleExecutionException { LogbookOperationParameters logbookOpStpParamStart; LogbookLifeCycleUnitParameters logbookLCParamEnd; ParametersChecker.checkParameter(ID_CHECK_FAILED, idUnit); JsonNode jsonNode = JsonHandler.createObjectNode(); boolean globalStep = true; boolean stepCheckPermission = true; boolean stepCheckRules = true; boolean stepMetadataUpdate = true; boolean stepStorageUpdate = true; boolean stepLFCCommit = true; final GUID idGUID; final GUID idRequest; try { idGUID = GUIDReader.getGUID(idUnit); idRequest = GUIDReader.getGUID(requestId); } catch (final InvalidGuidOperationException e) { LOGGER.error("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); throw new MetaDataNotFoundException("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); } final RequestParserMultiple parser = RequestParserHelper.getParser(queryJson); if (!(parser instanceof UpdateParserMultiple)) { parser.getRequest().reset(); throw new IllegalArgumentException("Request is not an update operation"); } final GUID updateOpGuidStart = idRequest; Boolean requestUpdateManagment = updateContainsManagmentFields(queryJson); String masterStpOperation = requestUpdateManagment ? STP_UPDATE_UNIT : STP_UPDATE_UNIT_DESC; try (MetaDataClient metaDataClient = metaDataClientFactory.getClient(); LogbookOperationsClient logbookOperationClient = logbookOperationsClientFactory.getClient(); LogbookLifeCyclesClient logbookLifeCycleClient = logbookLifeCyclesClientFactory.getClient()) { logbookOpStpParamStart = getLogbookOperationUpdateUnitParameters(updateOpGuidStart, updateOpGuidStart, StatusCode.STARTED, VitamLogbookMessages.getCodeOp(masterStpOperation, StatusCode.STARTED), idRequest, masterStpOperation, true); logbookOpStpParamStart.putParameterValue(LogbookParameterName.objectIdentifier, idUnit); logbookOpStpParamStart.putParameterValue(LogbookParameterName.outcomeDetail, STP_UPDATE_UNIT + "." + StatusCode.STARTED); logbookOperationClient.create(logbookOpStpParamStart); globalStep = false; stepCheckPermission = false; checkPermissions(requestUpdateManagment); stepCheckPermission = true; if (requestUpdateManagment) { stepCheckRules = false; checkAndUpdateRuleQuery((UpdateParserMultiple) parser); stepCheckRules = true; } try { queryJson = ((UpdateParserMultiple) parser).getRequest() .addActions(UpdateActionHelper.push(VitamFieldsHelper.operations(), updateOpGuidStart.toString())) .getFinalUpdate(); } catch (final InvalidCreateOperationException e) { LOGGER.error(e); throw new AccessInternalExecutionException(ERROR_ADD_CONDITION, e); } stepMetadataUpdate = false; jsonNode = metaDataClient.updateUnitById(queryJson, idUnit); stepMetadataUpdate = true; logbookLCParamEnd = getLogbookLifeCycleUpdateUnitParameters(updateOpGuidStart, StatusCode.OK, idGUID, UNIT_METADATA_UPDATE); logbookLCParamEnd.putParameterValue(LogbookParameterName.eventDetailData, getDiffMessageFor(jsonNode, idUnit)); stepLFCCommit = false; logbookLifeCycleClient.update(logbookLCParamEnd, LifeCycleStatusCode.LIFE_CYCLE_COMMITTED); stepLFCCommit = true; stepStorageUpdate = false; replaceStoredUnitMetadata(idUnit, requestId); stepStorageUpdate = true; globalStep = true; finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (final InvalidParseOperationException ipoe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, ipoe.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(PARSING_ERROR, ipoe); throw ipoe; } catch (final IllegalArgumentException iae) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(ILLEGAL_ARGUMENT, iae); throw iae; } catch (final MetaDataNotFoundException mdnfe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, DT_NO_EXTISTING); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_NOT_FOUND_ERROR, mdnfe); throw mdnfe; } catch (final MetaDataDocumentSizeException mddse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_DOCUMENT_SIZE_ERROR, mddse); throw new AccessInternalExecutionException(mddse); } catch (final LogbookClientServerException lcse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(DOCUMENT_CLIENT_SERVER_ERROR, lcse); throw new AccessInternalExecutionException(lcse); } catch (final MetaDataExecutionException mdee) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_EXECUTION_EXECUTION_ERROR, mdee); throw new AccessInternalExecutionException(mdee); } catch (final LogbookClientNotFoundException lcnfe) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_NOT_FOUND_ERROR, lcnfe); throw new AccessInternalExecutionException(lcnfe); } catch (final LogbookClientBadRequestException lcbre) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_BAD_REQUEST_ERROR, lcbre); throw new AccessInternalExecutionException(lcbre); } catch (final LogbookClientAlreadyExistsException e) { LOGGER.error(LOGBOOK_OPERATION_ALREADY_EXISTS, e); throw new AccessInternalExecutionException(e); } catch (final MetaDataClientServerException e) { LOGGER.error(METADATA_INTERNAL_SERVER_ERROR, e); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); throw new AccessInternalExecutionException(e); } catch (StorageClientException e) { try { finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (LogbookClientBadRequestException | LogbookClientNotFoundException | LogbookClientServerException e1) { LOGGER.error(STORAGE_SERVER_EXCEPTION, e1); } LOGGER.error(STORAGE_SERVER_EXCEPTION, e); throw new AccessInternalExecutionException(STORAGE_SERVER_EXCEPTION, e); } catch (ContentAddressableStorageException e) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(WORKSPACE_SERVER_EXCEPTION, e); } catch (AccessInternalRuleExecutionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_RULES, e); throw e; } catch (final UpdatePermissionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_PERMISSIONS, e); throw e; } catch (AccessInternalException e) { LOGGER.error(ARCHIVE_UNIT_NOT_FOUND, e); throw new AccessInternalExecutionException(e); } return jsonNode; } }
AccessInternalModuleImpl implements AccessInternalModule { @Override public JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId) throws MetaDataNotFoundException, IllegalArgumentException, InvalidParseOperationException, AccessInternalExecutionException, UpdatePermissionException, AccessInternalRuleExecutionException { LogbookOperationParameters logbookOpStpParamStart; LogbookLifeCycleUnitParameters logbookLCParamEnd; ParametersChecker.checkParameter(ID_CHECK_FAILED, idUnit); JsonNode jsonNode = JsonHandler.createObjectNode(); boolean globalStep = true; boolean stepCheckPermission = true; boolean stepCheckRules = true; boolean stepMetadataUpdate = true; boolean stepStorageUpdate = true; boolean stepLFCCommit = true; final GUID idGUID; final GUID idRequest; try { idGUID = GUIDReader.getGUID(idUnit); idRequest = GUIDReader.getGUID(requestId); } catch (final InvalidGuidOperationException e) { LOGGER.error("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); throw new MetaDataNotFoundException("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); } final RequestParserMultiple parser = RequestParserHelper.getParser(queryJson); if (!(parser instanceof UpdateParserMultiple)) { parser.getRequest().reset(); throw new IllegalArgumentException("Request is not an update operation"); } final GUID updateOpGuidStart = idRequest; Boolean requestUpdateManagment = updateContainsManagmentFields(queryJson); String masterStpOperation = requestUpdateManagment ? STP_UPDATE_UNIT : STP_UPDATE_UNIT_DESC; try (MetaDataClient metaDataClient = metaDataClientFactory.getClient(); LogbookOperationsClient logbookOperationClient = logbookOperationsClientFactory.getClient(); LogbookLifeCyclesClient logbookLifeCycleClient = logbookLifeCyclesClientFactory.getClient()) { logbookOpStpParamStart = getLogbookOperationUpdateUnitParameters(updateOpGuidStart, updateOpGuidStart, StatusCode.STARTED, VitamLogbookMessages.getCodeOp(masterStpOperation, StatusCode.STARTED), idRequest, masterStpOperation, true); logbookOpStpParamStart.putParameterValue(LogbookParameterName.objectIdentifier, idUnit); logbookOpStpParamStart.putParameterValue(LogbookParameterName.outcomeDetail, STP_UPDATE_UNIT + "." + StatusCode.STARTED); logbookOperationClient.create(logbookOpStpParamStart); globalStep = false; stepCheckPermission = false; checkPermissions(requestUpdateManagment); stepCheckPermission = true; if (requestUpdateManagment) { stepCheckRules = false; checkAndUpdateRuleQuery((UpdateParserMultiple) parser); stepCheckRules = true; } try { queryJson = ((UpdateParserMultiple) parser).getRequest() .addActions(UpdateActionHelper.push(VitamFieldsHelper.operations(), updateOpGuidStart.toString())) .getFinalUpdate(); } catch (final InvalidCreateOperationException e) { LOGGER.error(e); throw new AccessInternalExecutionException(ERROR_ADD_CONDITION, e); } stepMetadataUpdate = false; jsonNode = metaDataClient.updateUnitById(queryJson, idUnit); stepMetadataUpdate = true; logbookLCParamEnd = getLogbookLifeCycleUpdateUnitParameters(updateOpGuidStart, StatusCode.OK, idGUID, UNIT_METADATA_UPDATE); logbookLCParamEnd.putParameterValue(LogbookParameterName.eventDetailData, getDiffMessageFor(jsonNode, idUnit)); stepLFCCommit = false; logbookLifeCycleClient.update(logbookLCParamEnd, LifeCycleStatusCode.LIFE_CYCLE_COMMITTED); stepLFCCommit = true; stepStorageUpdate = false; replaceStoredUnitMetadata(idUnit, requestId); stepStorageUpdate = true; globalStep = true; finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (final InvalidParseOperationException ipoe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, ipoe.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(PARSING_ERROR, ipoe); throw ipoe; } catch (final IllegalArgumentException iae) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(ILLEGAL_ARGUMENT, iae); throw iae; } catch (final MetaDataNotFoundException mdnfe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, DT_NO_EXTISTING); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_NOT_FOUND_ERROR, mdnfe); throw mdnfe; } catch (final MetaDataDocumentSizeException mddse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_DOCUMENT_SIZE_ERROR, mddse); throw new AccessInternalExecutionException(mddse); } catch (final LogbookClientServerException lcse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(DOCUMENT_CLIENT_SERVER_ERROR, lcse); throw new AccessInternalExecutionException(lcse); } catch (final MetaDataExecutionException mdee) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_EXECUTION_EXECUTION_ERROR, mdee); throw new AccessInternalExecutionException(mdee); } catch (final LogbookClientNotFoundException lcnfe) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_NOT_FOUND_ERROR, lcnfe); throw new AccessInternalExecutionException(lcnfe); } catch (final LogbookClientBadRequestException lcbre) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_BAD_REQUEST_ERROR, lcbre); throw new AccessInternalExecutionException(lcbre); } catch (final LogbookClientAlreadyExistsException e) { LOGGER.error(LOGBOOK_OPERATION_ALREADY_EXISTS, e); throw new AccessInternalExecutionException(e); } catch (final MetaDataClientServerException e) { LOGGER.error(METADATA_INTERNAL_SERVER_ERROR, e); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); throw new AccessInternalExecutionException(e); } catch (StorageClientException e) { try { finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (LogbookClientBadRequestException | LogbookClientNotFoundException | LogbookClientServerException e1) { LOGGER.error(STORAGE_SERVER_EXCEPTION, e1); } LOGGER.error(STORAGE_SERVER_EXCEPTION, e); throw new AccessInternalExecutionException(STORAGE_SERVER_EXCEPTION, e); } catch (ContentAddressableStorageException e) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(WORKSPACE_SERVER_EXCEPTION, e); } catch (AccessInternalRuleExecutionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_RULES, e); throw e; } catch (final UpdatePermissionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_PERMISSIONS, e); throw e; } catch (AccessInternalException e) { LOGGER.error(ARCHIVE_UNIT_NOT_FOUND, e); throw new AccessInternalExecutionException(e); } return jsonNode; } AccessInternalModuleImpl(); @VisibleForTesting  AccessInternalModuleImpl(LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory, StorageClientFactory storageClientFactory,
        WorkspaceClientFactory workspaceClientFactory, AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory); }
AccessInternalModuleImpl implements AccessInternalModule { @Override public JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId) throws MetaDataNotFoundException, IllegalArgumentException, InvalidParseOperationException, AccessInternalExecutionException, UpdatePermissionException, AccessInternalRuleExecutionException { LogbookOperationParameters logbookOpStpParamStart; LogbookLifeCycleUnitParameters logbookLCParamEnd; ParametersChecker.checkParameter(ID_CHECK_FAILED, idUnit); JsonNode jsonNode = JsonHandler.createObjectNode(); boolean globalStep = true; boolean stepCheckPermission = true; boolean stepCheckRules = true; boolean stepMetadataUpdate = true; boolean stepStorageUpdate = true; boolean stepLFCCommit = true; final GUID idGUID; final GUID idRequest; try { idGUID = GUIDReader.getGUID(idUnit); idRequest = GUIDReader.getGUID(requestId); } catch (final InvalidGuidOperationException e) { LOGGER.error("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); throw new MetaDataNotFoundException("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); } final RequestParserMultiple parser = RequestParserHelper.getParser(queryJson); if (!(parser instanceof UpdateParserMultiple)) { parser.getRequest().reset(); throw new IllegalArgumentException("Request is not an update operation"); } final GUID updateOpGuidStart = idRequest; Boolean requestUpdateManagment = updateContainsManagmentFields(queryJson); String masterStpOperation = requestUpdateManagment ? STP_UPDATE_UNIT : STP_UPDATE_UNIT_DESC; try (MetaDataClient metaDataClient = metaDataClientFactory.getClient(); LogbookOperationsClient logbookOperationClient = logbookOperationsClientFactory.getClient(); LogbookLifeCyclesClient logbookLifeCycleClient = logbookLifeCyclesClientFactory.getClient()) { logbookOpStpParamStart = getLogbookOperationUpdateUnitParameters(updateOpGuidStart, updateOpGuidStart, StatusCode.STARTED, VitamLogbookMessages.getCodeOp(masterStpOperation, StatusCode.STARTED), idRequest, masterStpOperation, true); logbookOpStpParamStart.putParameterValue(LogbookParameterName.objectIdentifier, idUnit); logbookOpStpParamStart.putParameterValue(LogbookParameterName.outcomeDetail, STP_UPDATE_UNIT + "." + StatusCode.STARTED); logbookOperationClient.create(logbookOpStpParamStart); globalStep = false; stepCheckPermission = false; checkPermissions(requestUpdateManagment); stepCheckPermission = true; if (requestUpdateManagment) { stepCheckRules = false; checkAndUpdateRuleQuery((UpdateParserMultiple) parser); stepCheckRules = true; } try { queryJson = ((UpdateParserMultiple) parser).getRequest() .addActions(UpdateActionHelper.push(VitamFieldsHelper.operations(), updateOpGuidStart.toString())) .getFinalUpdate(); } catch (final InvalidCreateOperationException e) { LOGGER.error(e); throw new AccessInternalExecutionException(ERROR_ADD_CONDITION, e); } stepMetadataUpdate = false; jsonNode = metaDataClient.updateUnitById(queryJson, idUnit); stepMetadataUpdate = true; logbookLCParamEnd = getLogbookLifeCycleUpdateUnitParameters(updateOpGuidStart, StatusCode.OK, idGUID, UNIT_METADATA_UPDATE); logbookLCParamEnd.putParameterValue(LogbookParameterName.eventDetailData, getDiffMessageFor(jsonNode, idUnit)); stepLFCCommit = false; logbookLifeCycleClient.update(logbookLCParamEnd, LifeCycleStatusCode.LIFE_CYCLE_COMMITTED); stepLFCCommit = true; stepStorageUpdate = false; replaceStoredUnitMetadata(idUnit, requestId); stepStorageUpdate = true; globalStep = true; finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (final InvalidParseOperationException ipoe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, ipoe.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(PARSING_ERROR, ipoe); throw ipoe; } catch (final IllegalArgumentException iae) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(ILLEGAL_ARGUMENT, iae); throw iae; } catch (final MetaDataNotFoundException mdnfe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, DT_NO_EXTISTING); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_NOT_FOUND_ERROR, mdnfe); throw mdnfe; } catch (final MetaDataDocumentSizeException mddse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_DOCUMENT_SIZE_ERROR, mddse); throw new AccessInternalExecutionException(mddse); } catch (final LogbookClientServerException lcse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(DOCUMENT_CLIENT_SERVER_ERROR, lcse); throw new AccessInternalExecutionException(lcse); } catch (final MetaDataExecutionException mdee) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_EXECUTION_EXECUTION_ERROR, mdee); throw new AccessInternalExecutionException(mdee); } catch (final LogbookClientNotFoundException lcnfe) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_NOT_FOUND_ERROR, lcnfe); throw new AccessInternalExecutionException(lcnfe); } catch (final LogbookClientBadRequestException lcbre) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_BAD_REQUEST_ERROR, lcbre); throw new AccessInternalExecutionException(lcbre); } catch (final LogbookClientAlreadyExistsException e) { LOGGER.error(LOGBOOK_OPERATION_ALREADY_EXISTS, e); throw new AccessInternalExecutionException(e); } catch (final MetaDataClientServerException e) { LOGGER.error(METADATA_INTERNAL_SERVER_ERROR, e); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); throw new AccessInternalExecutionException(e); } catch (StorageClientException e) { try { finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (LogbookClientBadRequestException | LogbookClientNotFoundException | LogbookClientServerException e1) { LOGGER.error(STORAGE_SERVER_EXCEPTION, e1); } LOGGER.error(STORAGE_SERVER_EXCEPTION, e); throw new AccessInternalExecutionException(STORAGE_SERVER_EXCEPTION, e); } catch (ContentAddressableStorageException e) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(WORKSPACE_SERVER_EXCEPTION, e); } catch (AccessInternalRuleExecutionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_RULES, e); throw e; } catch (final UpdatePermissionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_PERMISSIONS, e); throw e; } catch (AccessInternalException e) { LOGGER.error(ARCHIVE_UNIT_NOT_FOUND, e); throw new AccessInternalExecutionException(e); } return jsonNode; } AccessInternalModuleImpl(); @VisibleForTesting  AccessInternalModuleImpl(LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory, StorageClientFactory storageClientFactory,
        WorkspaceClientFactory workspaceClientFactory, AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory); @Override JsonNode selectUnit(JsonNode jsonQuery); @Override JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit); @Override JsonNode selectObjectGroupById(JsonNode jsonQuery, String idObjectGroup); @Override Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit); @Override Response getAccessLog(JsonNode params); void checkClassificationLevel(JsonNode query); @Override JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId); @Override Response findDIPByOperationId(String id); @Override Response findTransferSIPByOperationId(String id); @Override JsonNode selectObjects(JsonNode jsonQuery); @Override JsonNode selectUnitsWithInheritedRules(JsonNode jsonQuery); }
AccessInternalModuleImpl implements AccessInternalModule { @Override public JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId) throws MetaDataNotFoundException, IllegalArgumentException, InvalidParseOperationException, AccessInternalExecutionException, UpdatePermissionException, AccessInternalRuleExecutionException { LogbookOperationParameters logbookOpStpParamStart; LogbookLifeCycleUnitParameters logbookLCParamEnd; ParametersChecker.checkParameter(ID_CHECK_FAILED, idUnit); JsonNode jsonNode = JsonHandler.createObjectNode(); boolean globalStep = true; boolean stepCheckPermission = true; boolean stepCheckRules = true; boolean stepMetadataUpdate = true; boolean stepStorageUpdate = true; boolean stepLFCCommit = true; final GUID idGUID; final GUID idRequest; try { idGUID = GUIDReader.getGUID(idUnit); idRequest = GUIDReader.getGUID(requestId); } catch (final InvalidGuidOperationException e) { LOGGER.error("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); throw new MetaDataNotFoundException("idUnit is not a valid GUID - " + METADATA_NOT_FOUND_ERROR, e); } final RequestParserMultiple parser = RequestParserHelper.getParser(queryJson); if (!(parser instanceof UpdateParserMultiple)) { parser.getRequest().reset(); throw new IllegalArgumentException("Request is not an update operation"); } final GUID updateOpGuidStart = idRequest; Boolean requestUpdateManagment = updateContainsManagmentFields(queryJson); String masterStpOperation = requestUpdateManagment ? STP_UPDATE_UNIT : STP_UPDATE_UNIT_DESC; try (MetaDataClient metaDataClient = metaDataClientFactory.getClient(); LogbookOperationsClient logbookOperationClient = logbookOperationsClientFactory.getClient(); LogbookLifeCyclesClient logbookLifeCycleClient = logbookLifeCyclesClientFactory.getClient()) { logbookOpStpParamStart = getLogbookOperationUpdateUnitParameters(updateOpGuidStart, updateOpGuidStart, StatusCode.STARTED, VitamLogbookMessages.getCodeOp(masterStpOperation, StatusCode.STARTED), idRequest, masterStpOperation, true); logbookOpStpParamStart.putParameterValue(LogbookParameterName.objectIdentifier, idUnit); logbookOpStpParamStart.putParameterValue(LogbookParameterName.outcomeDetail, STP_UPDATE_UNIT + "." + StatusCode.STARTED); logbookOperationClient.create(logbookOpStpParamStart); globalStep = false; stepCheckPermission = false; checkPermissions(requestUpdateManagment); stepCheckPermission = true; if (requestUpdateManagment) { stepCheckRules = false; checkAndUpdateRuleQuery((UpdateParserMultiple) parser); stepCheckRules = true; } try { queryJson = ((UpdateParserMultiple) parser).getRequest() .addActions(UpdateActionHelper.push(VitamFieldsHelper.operations(), updateOpGuidStart.toString())) .getFinalUpdate(); } catch (final InvalidCreateOperationException e) { LOGGER.error(e); throw new AccessInternalExecutionException(ERROR_ADD_CONDITION, e); } stepMetadataUpdate = false; jsonNode = metaDataClient.updateUnitById(queryJson, idUnit); stepMetadataUpdate = true; logbookLCParamEnd = getLogbookLifeCycleUpdateUnitParameters(updateOpGuidStart, StatusCode.OK, idGUID, UNIT_METADATA_UPDATE); logbookLCParamEnd.putParameterValue(LogbookParameterName.eventDetailData, getDiffMessageFor(jsonNode, idUnit)); stepLFCCommit = false; logbookLifeCycleClient.update(logbookLCParamEnd, LifeCycleStatusCode.LIFE_CYCLE_COMMITTED); stepLFCCommit = true; stepStorageUpdate = false; replaceStoredUnitMetadata(idUnit, requestId); stepStorageUpdate = true; globalStep = true; finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (final InvalidParseOperationException ipoe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, ipoe.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(PARSING_ERROR, ipoe); throw ipoe; } catch (final IllegalArgumentException iae) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(ILLEGAL_ARGUMENT, iae); throw iae; } catch (final MetaDataNotFoundException mdnfe) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, DT_NO_EXTISTING); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_NOT_FOUND_ERROR, mdnfe); throw mdnfe; } catch (final MetaDataDocumentSizeException mddse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_DOCUMENT_SIZE_ERROR, mddse); throw new AccessInternalExecutionException(mddse); } catch (final LogbookClientServerException lcse) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(DOCUMENT_CLIENT_SERVER_ERROR, lcse); throw new AccessInternalExecutionException(lcse); } catch (final MetaDataExecutionException mdee) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(METADATA_EXECUTION_EXECUTION_ERROR, mdee); throw new AccessInternalExecutionException(mdee); } catch (final LogbookClientNotFoundException lcnfe) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_NOT_FOUND_ERROR, lcnfe); throw new AccessInternalExecutionException(lcnfe); } catch (final LogbookClientBadRequestException lcbre) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(LOGBOOK_CLIENT_BAD_REQUEST_ERROR, lcbre); throw new AccessInternalExecutionException(lcbre); } catch (final LogbookClientAlreadyExistsException e) { LOGGER.error(LOGBOOK_OPERATION_ALREADY_EXISTS, e); throw new AccessInternalExecutionException(e); } catch (final MetaDataClientServerException e) { LOGGER.error(METADATA_INTERNAL_SERVER_ERROR, e); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); throw new AccessInternalExecutionException(e); } catch (StorageClientException e) { try { finalizeStepOperation(updateOpGuidStart, idRequest, idUnit, globalStep, stepCheckPermission, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, null, masterStpOperation, requestUpdateManagment); } catch (LogbookClientBadRequestException | LogbookClientNotFoundException | LogbookClientServerException e1) { LOGGER.error(STORAGE_SERVER_EXCEPTION, e1); } LOGGER.error(STORAGE_SERVER_EXCEPTION, e); throw new AccessInternalExecutionException(STORAGE_SERVER_EXCEPTION, e); } catch (ContentAddressableStorageException e) { rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, null, masterStpOperation, requestUpdateManagment); LOGGER.error(WORKSPACE_SERVER_EXCEPTION, e); } catch (AccessInternalRuleExecutionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_RULES, e); throw e; } catch (final UpdatePermissionException e) { ObjectNode evDetData = JsonHandler.createObjectNode(); evDetData.put(ERROR_CODE, e.getMessage()); rollBackLogbook(updateOpGuidStart, idRequest, idUnit, globalStep, stepMetadataUpdate, stepStorageUpdate, stepCheckRules, stepLFCCommit, stepCheckPermission, JsonHandler.unprettyPrint(evDetData), masterStpOperation, requestUpdateManagment); LOGGER.error(ERROR_CHECK_PERMISSIONS, e); throw e; } catch (AccessInternalException e) { LOGGER.error(ARCHIVE_UNIT_NOT_FOUND, e); throw new AccessInternalExecutionException(e); } return jsonNode; } AccessInternalModuleImpl(); @VisibleForTesting  AccessInternalModuleImpl(LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory, StorageClientFactory storageClientFactory,
        WorkspaceClientFactory workspaceClientFactory, AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory); @Override JsonNode selectUnit(JsonNode jsonQuery); @Override JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit); @Override JsonNode selectObjectGroupById(JsonNode jsonQuery, String idObjectGroup); @Override Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit); @Override Response getAccessLog(JsonNode params); void checkClassificationLevel(JsonNode query); @Override JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId); @Override Response findDIPByOperationId(String id); @Override Response findTransferSIPByOperationId(String id); @Override JsonNode selectObjects(JsonNode jsonQuery); @Override JsonNode selectUnitsWithInheritedRules(JsonNode jsonQuery);  }