BusinessObjectDataServiceImpl implements BusinessObjectDataService { @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override public BusinessObjectData updateBusinessObjectDataParents(BusinessObjectDataKey businessObjectDataKey, BusinessObjectDataParentsUpdateRequest businessObjectDataParentsUpdateRequest) { businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true); Assert.notNull(businessObjectDataParentsUpdateRequest, "A business object data parents update request must be specified."); businessObjectDataDaoHelper.validateBusinessObjectDataKeys(businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents()); BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey); if (BooleanUtils.isNotTrue(businessObjectDataEntity.getStatus().getPreRegistrationStatus())) { throw new IllegalArgumentException(String .format("Unable to update parents for business object data because it has \"%s\" status, which is not one of pre-registration statuses.", businessObjectDataEntity.getStatus().getCode())); } List<BusinessObjectDataEntity> businessObjectDataParents = businessObjectDataEntity.getBusinessObjectDataParents(); businessObjectDataParents.clear(); if (CollectionUtils.isNotEmpty(businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents())) { for (BusinessObjectDataKey businessObjectDataParentKey : businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents()) { BusinessObjectDataEntity businessObjectDataParentEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataParentKey); businessObjectDataParentEntity.getBusinessObjectDataChildren().add(businessObjectDataEntity); businessObjectDataParents.add(businessObjectDataParentEntity); } } businessObjectDataEntity = businessObjectDataDao.saveAndRefresh(businessObjectDataEntity); return businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity); }  @NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.READ) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectDataAvailability checkBusinessObjectDataAvailability(BusinessObjectDataAvailabilityRequest request); @NamespacePermission(fields = "#request?.businessObjectDataAvailabilityRequests?.![namespace]", permissions = NamespacePermissionEnum.READ) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectDataAvailabilityCollectionResponse checkBusinessObjectDataAvailabilityCollection(
        BusinessObjectDataAvailabilityCollectionRequest request); @PublishNotificationMessages @NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.WRITE) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectData createBusinessObjectData(BusinessObjectDataCreateRequest request); @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override BusinessObjectData deleteBusinessObjectData(BusinessObjectDataKey businessObjectDataKey, Boolean deleteFiles); @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) BusinessObjectData destroyBusinessObjectData(BusinessObjectDataKey businessObjectDataKey); @NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.READ) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectDataDdl generateBusinessObjectDataDdl(BusinessObjectDataDdlRequest request); @NamespacePermission(fields = "#request?.businessObjectDataDdlRequests?.![namespace]", permissions = NamespacePermissionEnum.READ) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectDataDdlCollectionResponse generateBusinessObjectDataDdlCollection(BusinessObjectDataDdlCollectionRequest request); @NamespacePermission(fields = "#businessObjectDefinitionKey.namespace", permissions = NamespacePermissionEnum.READ) @Override BusinessObjectDataKeys getAllBusinessObjectDataByBusinessObjectDefinition(BusinessObjectDefinitionKey businessObjectDefinitionKey); @NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.READ) @Override BusinessObjectDataKeys getAllBusinessObjectDataByBusinessObjectFormat(BusinessObjectFormatKey businessObjectFormatKey); @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.READ) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectData getBusinessObjectData(BusinessObjectDataKey businessObjectDataKey, String businessObjectFormatPartitionKey,
        String businessObjectDataStatus, Boolean includeBusinessObjectDataStatusHistory, Boolean includeStorageUnitStatusHistory,
        Boolean excludeBusinessObjectDataStorageFiles); @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.READ) @Override BusinessObjectDataVersions getBusinessObjectDataVersions(BusinessObjectDataKey businessObjectDataKey); @PublishNotificationMessages @NamespacePermission(fields = "#businessObjectDataInvalidateUnregisteredRequest.namespace", permissions = NamespacePermissionEnum.WRITE) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectDataInvalidateUnregisteredResponse invalidateUnregisteredBusinessObjectData(
        BusinessObjectDataInvalidateUnregisteredRequest businessObjectDataInvalidateUnregisteredRequest); @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) BusinessObjectData restoreBusinessObjectData(BusinessObjectDataKey businessObjectDataKey, Integer expirationInDays, String archiveRetrievalOption); @NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.READ) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectDataPartitions generateBusinessObjectDataPartitions(BusinessObjectDataPartitionsRequest request); @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override BusinessObjectData retryStoragePolicyTransition(BusinessObjectDataKey businessObjectDataKey,
        BusinessObjectDataRetryStoragePolicyTransitionRequest request); @NamespacePermission(fields = "#businessObjectDataSearchRequest.businessObjectDataSearchFilters[0].BusinessObjectDataSearchKeys[0].namespace", permissions = NamespacePermissionEnum.READ) @Override BusinessObjectDataSearchResultPagingInfoDto searchBusinessObjectData(Integer pageNum, Integer pageSize,
        BusinessObjectDataSearchRequest businessObjectDataSearchRequest); @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = {NamespacePermissionEnum.WRITE, NamespacePermissionEnum.WRITE_ATTRIBUTE}) @Override BusinessObjectData updateBusinessObjectDataAttributes(BusinessObjectDataKey businessObjectDataKey,
        BusinessObjectDataAttributesUpdateRequest businessObjectDataAttributesUpdateRequest); @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override BusinessObjectData updateBusinessObjectDataParents(BusinessObjectDataKey businessObjectDataKey,
        BusinessObjectDataParentsUpdateRequest businessObjectDataParentsUpdateRequest); @NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override BusinessObjectData updateBusinessObjectDataRetentionInformation(BusinessObjectDataKey businessObjectDataKey,
        BusinessObjectDataRetentionInformationUpdateRequest businessObjectDataRetentionInformationUpdateRequest); static final String NO_PARTITIONING_PARTITION_KEY; static final String NO_PARTITIONING_PARTITION_VALUE; static final String REASON_NOT_REGISTERED; }
@Test public void testUpdateBusinessObjectDataParents() { BusinessObjectDataKey businessObjectDataParentOneKey = new BusinessObjectDataKey(NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION, PARTITION_VALUE_2, SUBPARTITION_VALUES_2, DATA_VERSION); BusinessObjectDataKey businessObjectDataParentTwoKey = new BusinessObjectDataKey(NAMESPACE_3, BDEF_NAME_3, FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE_3, FORMAT_VERSION, PARTITION_VALUE_3, SUBPARTITION_VALUES_3, DATA_VERSION); BusinessObjectDataKey businessObjectDataChildKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); BusinessObjectDataEntity businessObjectDataParentOneEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataParentOneKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS); BusinessObjectDataEntity businessObjectDataParentTwoEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataParentTwoKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS); BusinessObjectDataEntity businessObjectDataChildEntity = businessObjectDataDaoTestHelper .createBusinessObjectDataEntity(businessObjectDataChildKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.UPLOADING); businessObjectDataParentOneEntity.getBusinessObjectDataChildren().add(businessObjectDataChildEntity); businessObjectDataChildEntity.getBusinessObjectDataParents().add(businessObjectDataParentOneEntity); BusinessObjectDataParentsUpdateRequest businessObjectDataParentsUpdateRequest = new BusinessObjectDataParentsUpdateRequest(Collections.singletonList(businessObjectDataParentTwoKey)); BusinessObjectData businessObjectData = new BusinessObjectData(); businessObjectData.setId(ID); when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataChildKey)).thenReturn(businessObjectDataChildEntity); when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataParentTwoKey)).thenReturn(businessObjectDataParentTwoEntity); when(businessObjectDataDao.saveAndRefresh(businessObjectDataChildEntity)).thenReturn(businessObjectDataChildEntity); when(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataChildEntity)).thenReturn(businessObjectData); BusinessObjectData result = businessObjectDataServiceImpl.updateBusinessObjectDataParents(businessObjectDataChildKey, businessObjectDataParentsUpdateRequest); verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataChildKey, true, true); verify(businessObjectDataDaoHelper).validateBusinessObjectDataKeys(businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents()); verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataChildKey); verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataParentTwoKey); verify(businessObjectDataDao).saveAndRefresh(businessObjectDataChildEntity); verify(businessObjectDataHelper).createBusinessObjectDataFromEntity(businessObjectDataChildEntity); verifyNoMoreInteractionsHelper(); assertEquals(businessObjectData, result); assertEquals(1, CollectionUtils.size(businessObjectDataChildEntity.getBusinessObjectDataParents())); assertEquals(businessObjectDataParentTwoEntity, businessObjectDataChildEntity.getBusinessObjectDataParents().get(0)); }
@Test public void testUpdateBusinessObjectDataParentsBusinessObjectDataNotInPreRegistrationState() { BusinessObjectDataKey businessObjectDataParentOneKey = new BusinessObjectDataKey(NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION, PARTITION_VALUE_2, SUBPARTITION_VALUES_2, DATA_VERSION); BusinessObjectDataKey businessObjectDataParentTwoKey = new BusinessObjectDataKey(NAMESPACE_3, BDEF_NAME_3, FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE_3, FORMAT_VERSION, PARTITION_VALUE_3, SUBPARTITION_VALUES_3, DATA_VERSION); BusinessObjectDataKey businessObjectDataChildKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); BusinessObjectDataEntity businessObjectDataParentOneEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataParentOneKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS); BusinessObjectDataEntity businessObjectDataChildEntity = businessObjectDataDaoTestHelper .createBusinessObjectDataEntity(businessObjectDataChildKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID); businessObjectDataParentOneEntity.getBusinessObjectDataChildren().add(businessObjectDataChildEntity); businessObjectDataChildEntity.getBusinessObjectDataParents().add(businessObjectDataParentOneEntity); BusinessObjectDataParentsUpdateRequest businessObjectDataParentsUpdateRequest = new BusinessObjectDataParentsUpdateRequest(Collections.singletonList(businessObjectDataParentTwoKey)); when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataChildKey)).thenReturn(businessObjectDataChildEntity); try { businessObjectDataServiceImpl.updateBusinessObjectDataParents(businessObjectDataChildKey, businessObjectDataParentsUpdateRequest); fail(); } catch (IllegalArgumentException e) { assertEquals(String .format("Unable to update parents for business object data because it has \"%s\" status, which is not one of pre-registration statuses.", BusinessObjectDataStatusEntity.VALID), e.getMessage()); } verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataChildKey, true, true); verify(businessObjectDataDaoHelper).validateBusinessObjectDataKeys(businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents()); verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataChildKey); verifyNoMoreInteractionsHelper(); assertEquals(1, CollectionUtils.size(businessObjectDataChildEntity.getBusinessObjectDataParents())); assertEquals(businessObjectDataParentOneEntity, businessObjectDataChildEntity.getBusinessObjectDataParents().get(0)); }
@Test public void testUpdateBusinessObjectDataParentsListOfParentsIsNull() { BusinessObjectDataKey businessObjectDataParentKey = new BusinessObjectDataKey(NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION, PARTITION_VALUE_2, SUBPARTITION_VALUES_2, DATA_VERSION); BusinessObjectDataKey businessObjectDataChildKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); BusinessObjectDataEntity businessObjectDataParentEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataParentKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS); BusinessObjectDataEntity businessObjectDataChildEntity = businessObjectDataDaoTestHelper .createBusinessObjectDataEntity(businessObjectDataChildKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.UPLOADING); businessObjectDataParentEntity.getBusinessObjectDataChildren().add(businessObjectDataChildEntity); businessObjectDataChildEntity.getBusinessObjectDataParents().add(businessObjectDataParentEntity); BusinessObjectDataParentsUpdateRequest businessObjectDataParentsUpdateRequest = new BusinessObjectDataParentsUpdateRequest(null); BusinessObjectData businessObjectData = new BusinessObjectData(); businessObjectData.setId(ID); when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataChildKey)).thenReturn(businessObjectDataChildEntity); when(businessObjectDataDao.saveAndRefresh(businessObjectDataChildEntity)).thenReturn(businessObjectDataChildEntity); when(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataChildEntity)).thenReturn(businessObjectData); BusinessObjectData result = businessObjectDataServiceImpl.updateBusinessObjectDataParents(businessObjectDataChildKey, businessObjectDataParentsUpdateRequest); verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataChildKey, true, true); verify(businessObjectDataDaoHelper).validateBusinessObjectDataKeys(businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents()); verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataChildKey); verify(businessObjectDataDao).saveAndRefresh(businessObjectDataChildEntity); verify(businessObjectDataHelper).createBusinessObjectDataFromEntity(businessObjectDataChildEntity); verifyNoMoreInteractionsHelper(); assertEquals(businessObjectData, result); assertTrue(CollectionUtils.isEmpty(businessObjectDataChildEntity.getBusinessObjectDataParents())); }