From 4b94d49a7821dbe875c03ea03f9aceca7d008106 Mon Sep 17 00:00:00 2001 From: Arthur Felde Date: Fri, 18 May 2018 20:12:38 -0400 Subject: [PATCH 01/11] Increment Maven POM version numbers to 0.71.0-SNAPSHOT --- herd-build/herd-build-tools/pom.xml | 2 +- herd-build/herd-docs/herd-docs-javadoc/pom.xml | 2 +- herd-build/herd-docs/herd-docs-swagger/pom.xml | 2 +- herd-build/herd-docs/pom.xml | 2 +- herd-build/herd-scripts/herd-scripts-bootstrap/pom.xml | 2 +- herd-build/herd-scripts/herd-scripts-cloud-formation/pom.xml | 2 +- herd-build/herd-scripts/herd-scripts-sql/pom.xml | 2 +- herd-build/herd-scripts/pom.xml | 2 +- herd-build/herd-swaggergen-maven-plugin/pom.xml | 2 +- herd-build/pom.xml | 2 +- herd-code/herd-app/pom.xml | 2 +- herd-code/herd-core/pom.xml | 2 +- herd-code/herd-dao/pom.xml | 2 +- herd-code/herd-model-api-15/pom.xml | 2 +- herd-code/herd-model-api/pom.xml | 2 +- herd-code/herd-model/pom.xml | 2 +- herd-code/herd-rest/pom.xml | 2 +- herd-code/herd-sdk/pom.xml | 2 +- herd-code/herd-service/pom.xml | 2 +- herd-code/herd-tools/herd-downloader/pom.xml | 2 +- .../herd-tools/herd-retention-expiration-destroyer/pom.xml | 2 +- .../herd-tools/herd-retention-expiration-exporter/pom.xml | 2 +- herd-code/herd-tools/herd-tools-common/pom.xml | 2 +- herd-code/herd-tools/herd-uploader/pom.xml | 2 +- herd-code/herd-tools/pom.xml | 2 +- herd-code/herd-ui/pom.xml | 2 +- herd-code/herd-war/pom.xml | 2 +- herd-code/pom.xml | 2 +- pom.xml | 4 ++-- 29 files changed, 30 insertions(+), 30 deletions(-) diff --git a/herd-build/herd-build-tools/pom.xml b/herd-build/herd-build-tools/pom.xml index 3569195ce7..3e2b463b53 100755 --- a/herd-build/herd-build-tools/pom.xml +++ b/herd-build/herd-build-tools/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-build - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd build tools diff --git a/herd-build/herd-docs/herd-docs-javadoc/pom.xml b/herd-build/herd-docs/herd-docs-javadoc/pom.xml index 4c0afae132..ef8526b793 100755 --- a/herd-build/herd-docs/herd-docs-javadoc/pom.xml +++ b/herd-build/herd-docs/herd-docs-javadoc/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-docs - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd docs javadoc diff --git a/herd-build/herd-docs/herd-docs-swagger/pom.xml b/herd-build/herd-docs/herd-docs-swagger/pom.xml index ede9088bd3..3b62821f2f 100755 --- a/herd-build/herd-docs/herd-docs-swagger/pom.xml +++ b/herd-build/herd-docs/herd-docs-swagger/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-docs - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd docs swagger diff --git a/herd-build/herd-docs/pom.xml b/herd-build/herd-docs/pom.xml index e384ca3896..0648cc48ad 100755 --- a/herd-build/herd-docs/pom.xml +++ b/herd-build/herd-docs/pom.xml @@ -22,7 +22,7 @@ org.finra.herd herd-build - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd docs diff --git a/herd-build/herd-scripts/herd-scripts-bootstrap/pom.xml b/herd-build/herd-scripts/herd-scripts-bootstrap/pom.xml index 0f133c7865..cc2aab4f6b 100755 --- a/herd-build/herd-scripts/herd-scripts-bootstrap/pom.xml +++ b/herd-build/herd-scripts/herd-scripts-bootstrap/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-scripts - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT This project contains the core herd EMR bootstrap scripts. diff --git a/herd-build/herd-scripts/herd-scripts-cloud-formation/pom.xml b/herd-build/herd-scripts/herd-scripts-cloud-formation/pom.xml index 346d8b2608..d3b33a8aa2 100755 --- a/herd-build/herd-scripts/herd-scripts-cloud-formation/pom.xml +++ b/herd-build/herd-scripts/herd-scripts-cloud-formation/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-scripts - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd scripts cloud formation diff --git a/herd-build/herd-scripts/herd-scripts-sql/pom.xml b/herd-build/herd-scripts/herd-scripts-sql/pom.xml index 58ede1bbf5..01fb9abf20 100755 --- a/herd-build/herd-scripts/herd-scripts-sql/pom.xml +++ b/herd-build/herd-scripts/herd-scripts-sql/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-scripts - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd scripts sql diff --git a/herd-build/herd-scripts/pom.xml b/herd-build/herd-scripts/pom.xml index b68bbf8da7..b4be09071a 100755 --- a/herd-build/herd-scripts/pom.xml +++ b/herd-build/herd-scripts/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-build - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd scripts diff --git a/herd-build/herd-swaggergen-maven-plugin/pom.xml b/herd-build/herd-swaggergen-maven-plugin/pom.xml index d5f616e70c..bc13d8e2f2 100755 --- a/herd-build/herd-swaggergen-maven-plugin/pom.xml +++ b/herd-build/herd-swaggergen-maven-plugin/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-build - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd swaggergen maven plugin diff --git a/herd-build/pom.xml b/herd-build/pom.xml index 50d3fa1bee..4e07008e47 100755 --- a/herd-build/pom.xml +++ b/herd-build/pom.xml @@ -22,7 +22,7 @@ org.finra.herd herd - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd build diff --git a/herd-code/herd-app/pom.xml b/herd-code/herd-app/pom.xml index 25a6ef986f..9d83a9aec6 100755 --- a/herd-code/herd-app/pom.xml +++ b/herd-code/herd-app/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-code - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd app diff --git a/herd-code/herd-core/pom.xml b/herd-code/herd-core/pom.xml index e508c023bb..2950d7636b 100755 --- a/herd-code/herd-core/pom.xml +++ b/herd-code/herd-core/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-code - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd core diff --git a/herd-code/herd-dao/pom.xml b/herd-code/herd-dao/pom.xml index 9d79fdf27c..02456c246e 100755 --- a/herd-code/herd-dao/pom.xml +++ b/herd-code/herd-dao/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-code - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT herd dao diff --git a/herd-code/herd-model-api-15/pom.xml b/herd-code/herd-model-api-15/pom.xml index c4aa7c2620..5a0a59afd4 100755 --- a/herd-code/herd-model-api-15/pom.xml +++ b/herd-code/herd-model-api-15/pom.xml @@ -21,7 +21,7 @@ org.finra.herd herd-code - 0.70.0-SNAPSHOT + 0.71.0-SNAPSHOT - 0.40.0 + 0.41.0 diff --git a/herd-code/herd-rest/src/main/java/org/finra/herd/rest/BusinessObjectDefinitionRestController.java b/herd-code/herd-rest/src/main/java/org/finra/herd/rest/BusinessObjectDefinitionRestController.java index 6da0134906..388cce77bb 100755 --- a/herd-code/herd-rest/src/main/java/org/finra/herd/rest/BusinessObjectDefinitionRestController.java +++ b/herd-code/herd-rest/src/main/java/org/finra/herd/rest/BusinessObjectDefinitionRestController.java @@ -30,8 +30,6 @@ import org.finra.herd.model.api.xml.BusinessObjectDefinition; import org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest; import org.finra.herd.model.api.xml.BusinessObjectDefinitionDescriptiveInformationUpdateRequest; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse; import org.finra.herd.model.api.xml.BusinessObjectDefinitionKey; import org.finra.herd.model.api.xml.BusinessObjectDefinitionKeys; import org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchRequest; @@ -187,23 +185,4 @@ public BusinessObjectDefinitionSearchResponse searchBusinessObjectDefinitions( { return businessObjectDefinitionService.searchBusinessObjectDefinitions(request, fields); } - - /** - * Searches across all business object definitions that are in search index per specified search filters and keys - * - * @param fields A comma-separated list of fields to be retrieved with each business object definition entity. Valid options: dataProviderName, - * shortDescription, displayName - * @param request the information needed to search across the business object definitions - * - * @return the retrieved business object definition list - */ - @RequestMapping(value = "/businessObjectDefinitions/indexSearch", method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) - @Secured(SecurityFunctions.FN_BUSINESS_OBJECT_DEFINITIONS_INDEX_SEARCH_POST) - public BusinessObjectDefinitionIndexSearchResponse indexSearchBusinessObjectDefinitions( - @RequestParam(value = "fields", required = false, defaultValue = "") Set fields, - @RequestBody BusinessObjectDefinitionIndexSearchRequest request) - { - return businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(request, fields); - } - } diff --git a/herd-code/herd-rest/src/test/java/org/finra/herd/rest/BusinessObjectDefinitionRestControllerIndexTest.java b/herd-code/herd-rest/src/test/java/org/finra/herd/rest/BusinessObjectDefinitionRestControllerIndexTest.java deleted file mode 100755 index d6fb0dc9a3..0000000000 --- a/herd-code/herd-rest/src/test/java/org/finra/herd/rest/BusinessObjectDefinitionRestControllerIndexTest.java +++ /dev/null @@ -1,175 +0,0 @@ -/* -* Copyright 2015 herd contributors -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.finra.herd.rest; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import org.apache.commons.lang3.StringUtils; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import org.finra.herd.model.api.xml.BusinessObjectDefinition; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey; -import org.finra.herd.model.api.xml.Facet; -import org.finra.herd.model.api.xml.TagKey; -import org.finra.herd.model.dto.FacetTypeEnum; -import org.finra.herd.model.dto.TagIndexSearchResponseDto; -import org.finra.herd.model.dto.TagTypeIndexSearchResponseDto; -import org.finra.herd.model.jpa.BusinessObjectDefinitionEntity; -import org.finra.herd.service.BusinessObjectDefinitionService; - -/** - * This class tests search index functionality within the business object definition REST controller. This separate test class was created because this one uses - * a mock business object definition service. - */ -public class BusinessObjectDefinitionRestControllerIndexTest extends AbstractRestTest -{ - @InjectMocks - private BusinessObjectDefinitionRestController businessObjectDefinitionRestController; - - @Mock - private BusinessObjectDefinitionService businessObjectDefinitionService; - - @Before - public void before() - { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testIndexSearchBusinessObjectDefinitions() - { - // Create a new tag key with a tag type and a tag code - TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE); - - // Create a new business object definition search key for use in the business object definition search key list - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, INCLUDE_TAG_HIERARCHY); - - // Create a new business object definition search key list with the tag key and the include tag hierarchy boolean flag - List businessObjectDefinitionSearchKeyList = new ArrayList<>(); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey); - - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - businessObjectDefinitionSearchFilterList.add(new BusinessObjectDefinitionSearchFilter(false, businessObjectDefinitionSearchKeyList)); - - - //Create a list of facet fields - List facetFields = new ArrayList<>(); - facetFields.add("Invalid"); - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, facetFields); - - // Create a new fields set that will be used when testing the index search business object definitions method - Set fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION); - - // Create a business object definition entity list to return from the search business object definitions by tags function - List businessObjectDefinitionEntityList = new ArrayList<>(); - businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper - .createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, - businessObjectDefinitionServiceTestHelper.getNewAttributes())); - businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper - .createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, - businessObjectDefinitionServiceTestHelper.getNewAttributes())); - - // Create a list to hold the business object definitions that will be returned as part of the search response - List businessObjectDefinitions = new ArrayList<>(); - - // Retrieve all unique business object definition entities and construct a list of business object definitions based on the requested fields. - for (BusinessObjectDefinitionEntity businessObjectDefinitionEntity : ImmutableSet.copyOf(businessObjectDefinitionEntityList)) - { - // Convert the business object definition entity to a business object definition and add it to the list of business object definitions that will be - // returned as a part of the search response - BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition(); - - // Populate the business object definition - businessObjectDefinition.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode()); - businessObjectDefinition.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName()); - businessObjectDefinition.setDataProviderName(businessObjectDefinitionEntity.getDataProvider().getName()); - businessObjectDefinition.setShortDescription(StringUtils.left(businessObjectDefinitionEntity.getDescription(), SHORT_DESCRIPTION_LENGTH)); - businessObjectDefinition.setDisplayName(businessObjectDefinitionEntity.getDisplayName()); - businessObjectDefinitions.add(businessObjectDefinition); - } - - List tagTypeIndexSearchResponseDtos = new ArrayList<>(); - List tagIndexSearchResponseDtos = new ArrayList<>(); - tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE, TAG_COUNT, TAG_DISPLAY_NAME)); - tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE_2, TAG_COUNT, TAG_DISPLAY_NAME_2)); - TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto = - new TagTypeIndexSearchResponseDto(TAG_TYPE, tagIndexSearchResponseDtos, TAG_TYPE_DISPLAY_NAME); - tagTypeIndexSearchResponseDtos.add(tagTypeIndexSearchResponseDto); - - List tagTypeFacets = new ArrayList<>(); - for (TagTypeIndexSearchResponseDto tagTypeIndexSearchResponse : ImmutableSet.copyOf(tagTypeIndexSearchResponseDtos)) - { - - List tagFacets = new ArrayList<>(); - - for (TagIndexSearchResponseDto tagIndexSearchResponseDto : tagTypeIndexSearchResponse.getTagIndexSearchResponseDtos()) - { - Facet tagFacet = new Facet(tagIndexSearchResponseDto.getTagDisplayName(), tagIndexSearchResponseDto.getCount(), FacetTypeEnum.TAG.value(), - tagIndexSearchResponseDto.getTagCode(), null); - tagFacets.add(tagFacet); - } - - tagTypeFacets.add(new Facet(tagTypeIndexSearchResponse.getDisplayName(), null, FacetTypeEnum.TAG_TYPE.value(), - tagTypeIndexSearchResponse.getCode(), tagFacets)); - } - - // Construct business object search response. - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = new BusinessObjectDefinitionIndexSearchResponse(); - businessObjectDefinitionSearchResponse.setBusinessObjectDefinitions(businessObjectDefinitions); - businessObjectDefinitionSearchResponse.setFacets(tagTypeFacets); - - // Mock the call to the business object definition service - when(businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionSearchRequest, fields)) - .thenReturn(businessObjectDefinitionSearchResponse); - - // Create a business object definition. - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponseFromRestCall = - businessObjectDefinitionRestController.indexSearchBusinessObjectDefinitions(fields, businessObjectDefinitionSearchRequest); - - // Verify the method call to businessObjectDefinitionService.indexAllBusinessObjectDefinitions() - verify(businessObjectDefinitionService, times(1)).indexSearchBusinessObjectDefinitions(businessObjectDefinitionSearchRequest, fields); - - // Validate the returned object. - assertThat("Business object definition index search response was null.", businessObjectDefinitionSearchResponseFromRestCall, not(nullValue())); - assertThat("Business object definition index search response was not correct.", businessObjectDefinitionSearchResponseFromRestCall, - is(businessObjectDefinitionSearchResponse)); - assertThat("Business object definition index search response was not an instance of BusinessObjectDefinitionSearchResponse.class.", - businessObjectDefinitionSearchResponseFromRestCall, instanceOf(BusinessObjectDefinitionIndexSearchResponse.class)); - } -} diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectDefinitionService.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectDefinitionService.java index 1214341586..655a848eb3 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectDefinitionService.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectDefinitionService.java @@ -21,8 +21,6 @@ import org.finra.herd.model.api.xml.BusinessObjectDefinition; import org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest; import org.finra.herd.model.api.xml.BusinessObjectDefinitionDescriptiveInformationUpdateRequest; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse; import org.finra.herd.model.api.xml.BusinessObjectDefinitionKey; import org.finra.herd.model.api.xml.BusinessObjectDefinitionKeys; import org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchRequest; @@ -138,14 +136,6 @@ public BusinessObjectDefinition getBusinessObjectDefinition(BusinessObjectDefini public BusinessObjectDefinitionSearchResponse searchBusinessObjectDefinitions(BusinessObjectDefinitionSearchRequest businessObjectDefinitionSearchRequest, Set fields); - /** - * Searches across all business object definitions that are in search index per specified search filters and keys - * - * @return the retrieved business object definition list - */ - public BusinessObjectDefinitionIndexSearchResponse indexSearchBusinessObjectDefinitions( - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest, Set fields); - /** * Update business object definition sample file * diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectDefinitionServiceImpl.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectDefinitionServiceImpl.java index 5e0f460cc9..b7b4ddd136 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectDefinitionServiceImpl.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectDefinitionServiceImpl.java @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -48,17 +47,15 @@ import org.finra.herd.core.HerdStringUtils; import org.finra.herd.core.helper.ConfigurationHelper; import org.finra.herd.dao.BusinessObjectDefinitionDao; -import org.finra.herd.dao.BusinessObjectDefinitionIndexSearchDao; import org.finra.herd.dao.IndexFunctionsDao; import org.finra.herd.dao.config.DaoSpringModuleConfig; +import org.finra.herd.dao.helper.TagDaoHelper; import org.finra.herd.model.annotation.NamespacePermission; import org.finra.herd.model.api.xml.Attribute; import org.finra.herd.model.api.xml.BusinessObjectDefinition; import org.finra.herd.model.api.xml.BusinessObjectDefinitionChangeEvent; import org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest; import org.finra.herd.model.api.xml.BusinessObjectDefinitionDescriptiveInformationUpdateRequest; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse; import org.finra.herd.model.api.xml.BusinessObjectDefinitionKey; import org.finra.herd.model.api.xml.BusinessObjectDefinitionKeys; import org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter; @@ -69,23 +66,15 @@ import org.finra.herd.model.api.xml.BusinessObjectFormatKey; import org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat; import org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormatUpdateRequest; -import org.finra.herd.model.api.xml.Facet; import org.finra.herd.model.api.xml.NamespacePermissionEnum; import org.finra.herd.model.api.xml.SampleDataFile; -import org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto; import org.finra.herd.model.dto.BusinessObjectDefinitionSampleFileUpdateDto; import org.finra.herd.model.dto.ConfigurationValue; -import org.finra.herd.model.dto.ElasticsearchResponseDto; -import org.finra.herd.model.dto.FacetTypeEnum; -import org.finra.herd.model.dto.SearchFilterType; import org.finra.herd.model.dto.SearchIndexUpdateDto; -import org.finra.herd.model.dto.TagIndexSearchResponseDto; -import org.finra.herd.model.dto.TagTypeIndexSearchResponseDto; import org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity; import org.finra.herd.model.jpa.BusinessObjectDefinitionEntity; import org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity; import org.finra.herd.model.jpa.BusinessObjectFormatEntity; -import org.finra.herd.model.jpa.SearchIndexTypeEntity; import org.finra.herd.model.jpa.StorageEntity; import org.finra.herd.model.jpa.TagEntity; import org.finra.herd.service.BusinessObjectDefinitionService; @@ -96,10 +85,8 @@ import org.finra.herd.service.helper.BusinessObjectDefinitionDaoHelper; import org.finra.herd.service.helper.BusinessObjectDefinitionHelper; import org.finra.herd.service.helper.BusinessObjectFormatDaoHelper; -import org.finra.herd.service.helper.SearchIndexDaoHelper; import org.finra.herd.service.helper.SearchIndexUpdateHelper; import org.finra.herd.service.helper.StorageDaoHelper; -import org.finra.herd.dao.helper.TagDaoHelper; import org.finra.herd.service.helper.TagHelper; /** @@ -154,12 +141,6 @@ public class BusinessObjectDefinitionServiceImpl implements BusinessObjectDefini @Autowired private SearchIndexUpdateHelper searchIndexUpdateHelper; - @Autowired - private SearchIndexDaoHelper searchIndexDaoHelper; - - @Autowired - private BusinessObjectDefinitionIndexSearchDao businessObjectDefinitionIndexSearchDao; - // Constant to hold the data provider name option for the business object definition search private static final String DATA_PROVIDER_NAME_FIELD = "dataprovidername"; @@ -530,140 +511,6 @@ public Set getValidFacetFields() return ImmutableSet.of(TAG_FACET_FIELD); } - @Override - public BusinessObjectDefinitionIndexSearchResponse indexSearchBusinessObjectDefinitions(BusinessObjectDefinitionIndexSearchRequest searchRequest, - Set fieldsRequested) - { - // Get the configured values for index name and document type - final String indexName = searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name()); - final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - - // Validate the business object definition search fields - validateSearchResponseFields(fieldsRequested); - - // Create a new object to hold the search index response - ElasticsearchResponseDto elasticsearchResponseDto; - - Set facetFields = new HashSet<>(); - if (CollectionUtils.isNotEmpty(searchRequest.getFacetFields())) - { - facetFields.addAll(validateFacetFields(new HashSet<>(searchRequest.getFacetFields()))); - } - - // If the request contains search filters - if (CollectionUtils.isNotEmpty(searchRequest.getBusinessObjectDefinitionSearchFilters())) - { - // Validate the search request. - validateBusinessObjectDefinitionIndexSearchRequest(searchRequest); - - List>> tagEntitiesPerSearchFilter = new ArrayList<>(); - - // Iterate through all search filters and extract tag keys - for (BusinessObjectDefinitionSearchFilter searchFilter : searchRequest.getBusinessObjectDefinitionSearchFilters()) - { - - List tagEntities = new ArrayList<>(); - Map> searchFilterTypeListMap = new HashMap<>(); - - if (BooleanUtils.isTrue(searchFilter.isIsExclusionSearchFilter())) - { - searchFilterTypeListMap.put(SearchFilterType.EXCLUSION_SEARCH_FILTER, tagEntities); - validateExclusionSearchFilter(searchFilter); - } - else - { - searchFilterTypeListMap.put(SearchFilterType.INCLUSION_SEARCH_FILTER, tagEntities); - } - - for (BusinessObjectDefinitionSearchKey searchKey : searchFilter.getBusinessObjectDefinitionSearchKeys()) - { - // Get the actual tag entity from its key. - // TODO: bulk fetch tags and their children from the search index after we start indexing tags - TagEntity tagEntity = tagDaoHelper.getTagEntity(searchKey.getTagKey()); - tagEntities.add(tagEntity); - - // If includeTagHierarchy is true, get list of children tag entities down the hierarchy of the specified tag. - if (BooleanUtils.isTrue(searchKey.isIncludeTagHierarchy())) - { - tagEntities.addAll(tagDaoHelper.getTagChildrenEntities(tagEntity)); - } - } - - // Collect all tag entities and their children (if included) into separate lists - tagEntitiesPerSearchFilter.add(searchFilterTypeListMap); - } - - // Use the tag type entities lists to search in the search index for business object definitions - elasticsearchResponseDto = - businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(indexName, documentType, tagEntitiesPerSearchFilter, facetFields); - } - else - { - // Else get all of the business object definitions - elasticsearchResponseDto = businessObjectDefinitionIndexSearchDao.findAllBusinessObjectDefinitions(indexName, documentType, facetFields); - } - - // Create a list to hold the business object definitions that will be returned as part of the search response - List businessObjectDefinitions = new ArrayList<>(); - - // Retrieve all unique business object definition entities and construct a list of business object definitions based on the requested fields. - if (elasticsearchResponseDto.getBusinessObjectDefinitionIndexSearchResponseDtos() != null) - { - for (BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto : ImmutableSet - .copyOf(elasticsearchResponseDto.getBusinessObjectDefinitionIndexSearchResponseDtos())) - { - // Convert the business object definition entity to a business object definition and - // add it to the list of business object definitions that will be - // returned as a part of the search response - businessObjectDefinitions.add(createBusinessObjectDefinitionFromDto(businessObjectDefinitionIndexSearchResponseDto, fieldsRequested)); - } - } - - List tagTypeFacets = null; - if (CollectionUtils.isNotEmpty(searchRequest.getFacetFields()) && elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos() != null) - { - tagTypeFacets = new ArrayList<>(); - //construct a list of facet information - for (TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto : elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos()) - { - - List tagFacets = new ArrayList<>(); - - for (TagIndexSearchResponseDto tagIndexSearchResponseDto : tagTypeIndexSearchResponseDto.getTagIndexSearchResponseDtos()) - { - Facet tagFacet = new Facet(tagIndexSearchResponseDto.getTagDisplayName(), tagIndexSearchResponseDto.getCount(), FacetTypeEnum.TAG.value(), - tagIndexSearchResponseDto.getTagCode(), null); - tagFacets.add(tagFacet); - } - - tagTypeFacets.add( - new Facet(tagTypeIndexSearchResponseDto.getDisplayName(), null, FacetTypeEnum.TAG_TYPE.value(), tagTypeIndexSearchResponseDto.getCode(), - tagFacets)); - } - } - - // Construct business object search response. - BusinessObjectDefinitionIndexSearchResponse searchResponse = new BusinessObjectDefinitionIndexSearchResponse(); - searchResponse.setBusinessObjectDefinitions(businessObjectDefinitions); - searchResponse.setFacets(tagTypeFacets); - return searchResponse; - } - - /** - * Private validate method to validate the exclusion search filter. Asserts that the isIncludeTagHierarchy flag is false, because the isIncludeTagHierarchy - * option should not be used at the same time as the exclusion option. - * - * @param searchFilter the search filter to validate - */ - private void validateExclusionSearchFilter(BusinessObjectDefinitionSearchFilter searchFilter) - { - for (BusinessObjectDefinitionSearchKey searchKey : searchFilter.getBusinessObjectDefinitionSearchKeys()) - { - Assert.isTrue(!BooleanUtils.isTrue(searchKey.isIncludeTagHierarchy()), - "IsExclusionSearchFilter and includeTagHierarchy cannot both be true for a business object definition search filter."); - } - } - @Override public BusinessObjectDefinitionSearchResponse searchBusinessObjectDefinitions(BusinessObjectDefinitionSearchRequest request, Set fields) { @@ -1007,30 +854,6 @@ private void validateBusinessObjectDefinitionSearchRequest(BusinessObjectDefinit } } - /** - * Validate the business object definition index search request. This method also trims the request parameters. - * - * @param businessObjectDefinitionIndexSearchRequest the business object definition search request - */ - private void validateBusinessObjectDefinitionIndexSearchRequest(BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest) - { - if (CollectionUtils.isNotEmpty(businessObjectDefinitionIndexSearchRequest.getBusinessObjectDefinitionSearchFilters())) - { - // Iterate through the search-filters and validate tag-keys. - for (BusinessObjectDefinitionSearchFilter searchFilter : businessObjectDefinitionIndexSearchRequest.getBusinessObjectDefinitionSearchFilters()) - { - // Validate that all search-filters have at least one search-key. - Assert.isTrue(CollectionUtils.isNotEmpty(searchFilter.getBusinessObjectDefinitionSearchKeys()), "At least one search key must be specified."); - - // Validate all tag-keys for each search-key. - for (BusinessObjectDefinitionSearchKey searchKey : searchFilter.getBusinessObjectDefinitionSearchKeys()) - { - tagHelper.validateTagKey(searchKey.getTagKey()); - } - } - } - } - @Override public void updateBusinessObjectDefinitionEntitySampleFile(BusinessObjectDefinitionKey businessObjectDefinitionKey, BusinessObjectDefinitionSampleFileUpdateDto businessObjectDefinitionSampleFileUpdateDto) @@ -1175,44 +998,4 @@ private Map convertBusinessObjectDefinitionEntityListToJSONStrin return businessObjectDefinitionJSONMap; } - - /** - * Creates a light-weight business object definition from a dto based on a set of requested fields. - * - * @param businessObjectDefinitionIndexSearchResponseDto the specified business object definition index search dto - * @param fields the set of requested fields - * - * @return the light-weight business object definition - */ - private BusinessObjectDefinition createBusinessObjectDefinitionFromDto( - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto, Set fields) - { - BusinessObjectDefinition definition = new BusinessObjectDefinition(); - - // Populate namespace and business object definition name fields by default - definition.setNamespace(businessObjectDefinitionIndexSearchResponseDto.getNamespace().getCode()); - definition.setBusinessObjectDefinitionName(businessObjectDefinitionIndexSearchResponseDto.getName()); - - // Decorate object with only the required fields - if (fields.contains(DATA_PROVIDER_NAME_FIELD)) - { - definition.setDataProviderName(businessObjectDefinitionIndexSearchResponseDto.getDataProvider().getName()); - } - - if (fields.contains(SHORT_DESCRIPTION_FIELD)) - { - // Get the configured value for short description's length - Integer shortDescMaxLength = configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class); - - definition - .setShortDescription(HerdStringUtils.getShortDescription(businessObjectDefinitionIndexSearchResponseDto.getDescription(), shortDescMaxLength)); - } - - if (fields.contains(DISPLAY_NAME_FIELD)) - { - definition.setDisplayName(businessObjectDefinitionIndexSearchResponseDto.getDisplayName()); - } - - return definition; - } } diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectDefinitionServiceIndexTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectDefinitionServiceIndexTest.java index 8e674302bd..85a769dce1 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectDefinitionServiceIndexTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectDefinitionServiceIndexTest.java @@ -24,7 +24,6 @@ import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; @@ -35,16 +34,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.concurrent.Future; import com.fasterxml.jackson.core.JsonLocation; import com.fasterxml.jackson.core.JsonParseException; -import com.google.common.collect.Sets; -import org.apache.commons.collections.CollectionUtils; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -54,28 +49,14 @@ import org.finra.herd.core.helper.ConfigurationHelper; import org.finra.herd.dao.BusinessObjectDefinitionDao; -import org.finra.herd.dao.BusinessObjectDefinitionIndexSearchDao; import org.finra.herd.dao.IndexFunctionsDao; import org.finra.herd.dao.helper.JsonHelper; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter; -import org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey; -import org.finra.herd.model.api.xml.TagKey; -import org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto; +import org.finra.herd.dao.helper.TagDaoHelper; import org.finra.herd.model.dto.ConfigurationValue; -import org.finra.herd.model.dto.DataProvider; -import org.finra.herd.model.dto.ElasticsearchResponseDto; -import org.finra.herd.model.dto.Namespace; import org.finra.herd.model.dto.SearchIndexUpdateDto; -import org.finra.herd.model.dto.TagIndexSearchResponseDto; -import org.finra.herd.model.dto.TagTypeIndexSearchResponseDto; import org.finra.herd.model.jpa.BusinessObjectDefinitionEntity; -import org.finra.herd.model.jpa.TagEntity; import org.finra.herd.service.helper.BusinessObjectDefinitionHelper; import org.finra.herd.service.helper.ConfigurationDaoHelper; -import org.finra.herd.service.helper.SearchIndexDaoHelper; -import org.finra.herd.dao.helper.TagDaoHelper; import org.finra.herd.service.helper.TagHelper; import org.finra.herd.service.impl.BusinessObjectDefinitionServiceImpl; @@ -90,9 +71,6 @@ public class BusinessObjectDefinitionServiceIndexTest extends AbstractServiceTes @Mock private BusinessObjectDefinitionHelper businessObjectDefinitionHelper; - @Mock - private BusinessObjectDefinitionIndexSearchDao businessObjectDefinitionIndexSearchDao; - @InjectMocks private BusinessObjectDefinitionServiceImpl businessObjectDefinitionService; @@ -114,9 +92,6 @@ public class BusinessObjectDefinitionServiceIndexTest extends AbstractServiceTes @Mock private TagHelper tagHelper; - @Mock - private SearchIndexDaoHelper searchIndexDaoHelper; - @Before public void before() { @@ -124,7 +99,7 @@ public void before() } @Test - public void testIndexValidateBusinessObjectDefinitions() throws Exception + public void testIndexValidateBusinessObjectDefinitions() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -164,7 +139,7 @@ public void testIndexValidateBusinessObjectDefinitions() throws Exception } @Test - public void testIndexSizeCheckValidationBusinessObjectDefinitions() throws Exception + public void testIndexSizeCheckValidationBusinessObjectDefinitions() { // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); @@ -184,7 +159,7 @@ public void testIndexSizeCheckValidationBusinessObjectDefinitions() throws Excep } @Test - public void testIndexSizeCheckValidationBusinessObjectDefinitionsFalse() throws Exception + public void testIndexSizeCheckValidationBusinessObjectDefinitionsFalse() { // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); @@ -204,7 +179,7 @@ public void testIndexSizeCheckValidationBusinessObjectDefinitionsFalse() throws } @Test - public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitions() throws Exception + public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitions() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -237,7 +212,7 @@ public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitions() th } @Test - public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitionsFalse() throws Exception + public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitionsFalse() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -270,7 +245,7 @@ public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitionsFalse } @Test - public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitionsObjectMappingException() throws Exception + public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitionsObjectMappingException() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -304,7 +279,7 @@ public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitionsObjec } @Test - public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitions() throws Exception + public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitions() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -337,7 +312,7 @@ public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitions() th } @Test - public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitionsFalse() throws Exception + public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitionsFalse() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -370,7 +345,7 @@ public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitionsFalse } @Test - public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitionsObjectMappingException() throws Exception + public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitionsObjectMappingException() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -404,659 +379,7 @@ public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitionsObjec } @Test - public void testIndexSearchBusinessObjectDefinitionsIncludeTagHierarchy() - { - // Create a new tag key with a tag type and a tag code - TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE); - - // Create a new business object definition search key for use in the business object definition search key list - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, INCLUDE_TAG_HIERARCHY); - - // Create a new business object definition search key list with the tag key and the include tag hierarchy boolean flag - List businessObjectDefinitionSearchKeyList = new ArrayList<>(); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey); - - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - businessObjectDefinitionSearchFilterList - .add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList)); - - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>()); - - // Create a new fields set that will be used when testing the index search business object definitions method - Set fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION); - - // Create a tag entity to return from the tag dao helper get tag entity method - TagEntity tagEntity = new TagEntity(); - tagEntity.setTagCode(TAG_CODE); - - // Create a tag child entity to enter into the tag children entities list - TagEntity tagChildEntity = new TagEntity(); - tagChildEntity.setTagCode(TAG_CODE_2); - - // Create a tag children entity list to return from the tag dao helper tag children entities method - List tagChildrenEntityList = new ArrayList<>(); - tagChildrenEntityList.add(tagChildEntity); - - List businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>(); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, - new Namespace(NAMESPACE)); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, - new Namespace(NAMESPACE)); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2); - - ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto(); - elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList); - - // Mock the call to external methods - when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)) - .thenReturn(SHORT_DESCRIPTION_LENGTH); - when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME); - when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); - when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity); - when(tagDaoHelper.getTagChildrenEntities(tagEntity)).thenReturn(tagChildrenEntityList); - - when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto); - - // Call the method under test - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = - businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields); - - assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", - businessObjectDefinitionSearchResponse, not(nullValue())); - - assertThat("The first business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME)); - - assertThat("The second business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2)); - - // Verify the calls to external methods - verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class); - verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF); - verify(tagHelper).validateTagKey(tagKey); - verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey()); - verify(tagDaoHelper).getTagChildrenEntities(tagEntity); - verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any()); - verifyNoMoreInteractionsHelper(); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionsDoNotIncludeTagHierarchy() - { - // Create a new tag key with a tag type and a tag code - TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE); - - // Create a new business object definition search key for use in the business object definition search key list - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, NOT_INCLUDE_TAG_HIERARCHY); - - // Create a new business object definition search key list with the tag key and the include tag hierarchy boolean flag - List businessObjectDefinitionSearchKeyList = new ArrayList<>(); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey); - - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - businessObjectDefinitionSearchFilterList - .add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList)); - - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>()); - - // Create a new fields set that will be used when testing the index search business object definitions method - Set fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION); - - // Create a tag entity to return from the tag dao helper get tag entity method - TagEntity tagEntity = new TagEntity(); - tagEntity.setTagCode(TAG_CODE); - - List businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>(); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, - new Namespace(NAMESPACE)); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, - new Namespace(NAMESPACE)); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2); - - ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto(); - elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList); - - // Mock the call to external methods - when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)) - .thenReturn(SHORT_DESCRIPTION_LENGTH); - when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); - when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity); - when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto); - - // Call the method under test - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = - businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields); - - assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", - businessObjectDefinitionSearchResponse, not(nullValue())); - - assertThat("The first business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME)); - - assertThat("The second business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2)); - - // Verify the calls to external methods - verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class); - verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - verify(tagHelper).validateTagKey(tagKey); - verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey()); - verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any()); - verifyNoMoreInteractionsHelper(); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionWithFacetFieldTag() - { - //Create a list of facet fields - List facetFields = new ArrayList<>(); - facetFields.add("TAG"); - indexSearchBusinessObjectDefinitionsFacetFields(facetFields); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionWithFacetFieldTagWhiteSpace() - { - //Create a list of facet fields - List facetFields = new ArrayList<>(); - facetFields.add(addWhitespace("TAG")); - indexSearchBusinessObjectDefinitionsFacetFields(facetFields); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionWithFacetFieldTagMixedCase() - { - //Create a list of facet fields - List facetFields = new ArrayList<>(); - facetFields.add(("TaG")); - indexSearchBusinessObjectDefinitionsFacetFields(facetFields); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionReturnsEmptyResponseForEmptyTagEntities() - { - // Create a tag key. - TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE); - - // Create a tag entity. - TagEntity tagEntity = new TagEntity(); - - // Create a new business object definition search key for use in the business object definition search key list with an empty tag key - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, NOT_INCLUDE_TAG_HIERARCHY); - - // Create a new business object definition search key list with the tag key and the include tag hierarchy boolean flag - List businessObjectDefinitionSearchKeyList = new ArrayList<>(); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey); - - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - businessObjectDefinitionSearchFilterList - .add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList)); - - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>()); - - // Mock the call to external methods - when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)) - .thenReturn(SHORT_DESCRIPTION_LENGTH); - when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME); - when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); - when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity); - when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())) - .thenReturn(new ElasticsearchResponseDto()); - - // Call the method under test - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = - businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, new HashSet<>()); - - assertThat("Expected empty response", CollectionUtils.isEmpty(businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions())); - - // Verify the calls to external methods - verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF); - verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - verify(tagHelper).validateTagKey(tagKey); - verify(tagDaoHelper).getTagEntity(tagKey); - verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any()); - verifyNoMoreInteractionsHelper(); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionWithFacetsReturnsEmptyResponseForEmptyTagEntities() - { - // Create a tag key. - TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE); - - // Create a tag entity. - TagEntity tagEntity = new TagEntity(); - - // Create a new business object definition search key for use in the business object definition search key list with an empty tag key - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, NOT_INCLUDE_TAG_HIERARCHY); - - // Create a new business object definition search key list with the tag key and the include tag hierarchy boolean flag - List businessObjectDefinitionSearchKeyList = new ArrayList<>(); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey); - - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - businessObjectDefinitionSearchFilterList - .add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList)); - - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, Collections.singletonList("TAG")); - - // Mock the call to external methods - when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)) - .thenReturn(SHORT_DESCRIPTION_LENGTH); - when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME); - when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); - when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity); - when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())) - .thenReturn(new ElasticsearchResponseDto()); - - // Call the method under test - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = - businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, new HashSet<>()); - - assertThat("Expected empty response", CollectionUtils.isEmpty(businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions())); - - // Verify the calls to external methods - verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF); - verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - verify(tagHelper).validateTagKey(tagKey); - verify(tagDaoHelper).getTagEntity(tagKey); - verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any()); - verifyNoMoreInteractionsHelper(); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionsWithMultipleTagsIncludeTagHierarchy() - { - // Create new tag keys - TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE); - TagKey tagKeyTwo = new TagKey(TAG_TYPE_2, TAG_CODE_2); - - // Create a new business object definition search key for use in the business object definition search key list - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, INCLUDE_TAG_HIERARCHY); - - // Create another new business object definition search key for use in the business object definition search key list - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKeyTwo = new BusinessObjectDefinitionSearchKey(tagKeyTwo, INCLUDE_TAG_HIERARCHY); - - // Create a new business object definition search key list with both the tag keys and the include tag hierarchy boolean flag - List businessObjectDefinitionSearchKeyList = new ArrayList<>(); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKeyTwo); - - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - businessObjectDefinitionSearchFilterList - .add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList)); - - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>()); - - // Create a new fields set that will be used when testing the index search business object definitions method - Set fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION); - - // Create a tag entity to return from the tag dao helper get tag entity method - TagEntity tagEntity = new TagEntity(); - tagEntity.setTagCode(TAG_CODE); - - // Create a tag entity to return from the tag dao helper get tag entity method - TagEntity tagEntityTwo = new TagEntity(); - tagEntity.setTagCode(TAG_CODE_2); - - // Create a tag child entity to enter into the tag children entities list - TagEntity tagChildEntity = new TagEntity(); - tagChildEntity.setTagCode(TAG_CODE_2); - - // Create a tag children entity list to return from the tag dao helper tag children entities method - List tagChildrenEntityList = new ArrayList<>(); - tagChildrenEntityList.add(tagChildEntity); - - List businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>(); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, - new Namespace(NAMESPACE)); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, - new Namespace(NAMESPACE)); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2); - - ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto(); - elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList); - - // Mock the call to external methods - when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)) - .thenReturn(SHORT_DESCRIPTION_LENGTH); - when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME); - when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); - when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity); - when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey())).thenReturn(tagEntityTwo); - when(tagDaoHelper.getTagChildrenEntities(tagEntity)).thenReturn(tagChildrenEntityList); - - when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto); - - // Call the method under test - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = - businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields); - - assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", - businessObjectDefinitionSearchResponse, not(nullValue())); - - assertThat("The first business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME)); - - assertThat("The second business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2)); - - // Verify the calls to external methods - verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class); - verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF); - verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKey.getTagKey()); - verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKeyTwo.getTagKey()); - verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey()); - verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey()); - verify(tagDaoHelper).getTagChildrenEntities(tagEntity); - verify(tagDaoHelper).getTagChildrenEntities(tagEntityTwo); - verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any()); - verifyNoMoreInteractionsHelper(); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionsWithMultipleTagsDoNotIncludeTagHierarchy() - { - // Create new tag keys - TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE); - TagKey tagKeyTwo = new TagKey(TAG_TYPE_2, TAG_CODE_2); - - // Create a new business object definition search key for use in the business object definition search key list - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, NOT_INCLUDE_TAG_HIERARCHY); - - // Create another new business object definition search key for use in the business object definition search key list - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKeyTwo = new BusinessObjectDefinitionSearchKey(tagKeyTwo, NOT_INCLUDE_TAG_HIERARCHY); - - // Create a new business object definition search key list with both the tag keys and the include tag hierarchy boolean flag - List businessObjectDefinitionSearchKeyList = new ArrayList<>(); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKeyTwo); - - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - businessObjectDefinitionSearchFilterList - .add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList)); - - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>()); - - // Create a new fields set that will be used when testing the index search business object definitions method - Set fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION); - - // Create a tag entity to return from the tag dao helper get tag entity method - TagEntity tagEntity = new TagEntity(); - tagEntity.setTagCode(TAG_CODE); - - // Create a tag entity to return from the tag dao helper get tag entity method - TagEntity tagEntityTwo = new TagEntity(); - tagEntity.setTagCode(TAG_CODE_2); - - List businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>(); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, - new Namespace(NAMESPACE)); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, - new Namespace(NAMESPACE)); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2); - - ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto(); - elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList); - - // Mock the call to external methods - when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)) - .thenReturn(SHORT_DESCRIPTION_LENGTH); - when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME); - when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); - when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity); - when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey())).thenReturn(tagEntityTwo); - - when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto); - - // Call the method under test - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = - businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields); - - assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", - businessObjectDefinitionSearchResponse, not(nullValue())); - - assertThat("The first business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME)); - - assertThat("The second business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2)); - - // Verify the calls to external methods - verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class); - verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF); - verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKey.getTagKey()); - verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKeyTwo.getTagKey()); - verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey()); - verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey()); - verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any()); - verifyNoMoreInteractionsHelper(); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionsWithMultipleTagsWithIsExclusionSearchFilter() - { - // Create new tag keys - TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE); - TagKey tagKeyTwo = new TagKey(TAG_TYPE_2, TAG_CODE_2); - - // Create a new business object definition search key for use in the business object definition search key list - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, NOT_INCLUDE_TAG_HIERARCHY); - - // Create another new business object definition search key for use in the business object definition search key list - BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKeyTwo = new BusinessObjectDefinitionSearchKey(tagKeyTwo, NOT_INCLUDE_TAG_HIERARCHY); - - // Create a new business object definition search key list with both the tag keys and the include tag hierarchy boolean flag - List businessObjectDefinitionSearchKeyList = new ArrayList<>(); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey); - businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKeyTwo); - - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - businessObjectDefinitionSearchFilterList.add(new BusinessObjectDefinitionSearchFilter(true, businessObjectDefinitionSearchKeyList)); - - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>()); - - // Create a new fields set that will be used when testing the index search business object definitions method - Set fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION); - - // Create a tag entity to return from the tag dao helper get tag entity method - TagEntity tagEntity = new TagEntity(); - tagEntity.setTagCode(TAG_CODE); - - // Create a tag entity to return from the tag dao helper get tag entity method - TagEntity tagEntityTwo = new TagEntity(); - tagEntity.setTagCode(TAG_CODE_2); - - List businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>(); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, - new Namespace(NAMESPACE)); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, - new Namespace(NAMESPACE)); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2); - - ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto(); - elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList); - - // Mock the call to external methods - when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)) - .thenReturn(SHORT_DESCRIPTION_LENGTH); - when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME); - when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); - when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity); - when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey())).thenReturn(tagEntityTwo); - when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto); - - // Call the method under test - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = - businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields); - - assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", - businessObjectDefinitionSearchResponse, not(nullValue())); - - assertThat("The first business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME)); - - assertThat("The second business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2)); - - // Verify the calls to external methods - verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class); - verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF); - verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKey.getTagKey()); - verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKeyTwo.getTagKey()); - verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey()); - verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey()); - verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any()); - verifyNoMoreInteractionsHelper(); - } - - @Test - public void testIndexSearchBusinessObjectDefinitionsInvalidFacet() - { - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - - //Create a list of facet fields - List facetFields = new ArrayList<>(); - facetFields.add("Invalid"); - - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, facetFields); - - // Create a new fields set that will be used when testing the index search business object definitions method - Set fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION); - - // Mock the call to external methods - when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME); - when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); - - // Call the method under test - try - { - businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields); - fail("Should have caught an exception."); - } - catch (IllegalArgumentException illegalArgumentException) - { - assertThat("The IllegalArgumentException message is not correct.", illegalArgumentException.getMessage(), - is("Facet field \"invalid\" is not supported.")); - } - // Verify the calls to external methods - verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF); - verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - verifyNoMoreInteractionsHelper(); - } - - private void indexSearchBusinessObjectDefinitionsFacetFields(List facetFields) - { - // Create a new business object definition search filter list with the new business object definition search key list - List businessObjectDefinitionSearchFilterList = new ArrayList<>(); - - // Create a new business object definition search request that will be used when testing the index search business object definitions method - BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = - new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, facetFields); - - // Create a new fields set that will be used when testing the index search business object definitions method - Set fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION); - - List businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>(); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, - new Namespace(NAMESPACE)); - BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = - new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, - new Namespace(NAMESPACE)); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1); - businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2); - - List tagTypeIndexSearchResponseDtos = new ArrayList<>(); - List tagIndexSearchResponseDtos = new ArrayList<>(); - tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE, TAG_COUNT, TAG_DISPLAY_NAME)); - tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE_2, TAG_COUNT, TAG_DISPLAY_NAME_2)); - TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto = - new TagTypeIndexSearchResponseDto(TAG_TYPE, tagIndexSearchResponseDtos, TAG_TYPE_DISPLAY_NAME); - tagTypeIndexSearchResponseDtos.add(tagTypeIndexSearchResponseDto); - - ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto(); - elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList); - elasticsearchResponseDto.setTagTypeIndexSearchResponseDtos(tagTypeIndexSearchResponseDtos); - - // Mock the call to external methods - when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)) - .thenReturn(SHORT_DESCRIPTION_LENGTH); - when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); - - when(businessObjectDefinitionIndexSearchDao.findAllBusinessObjectDefinitions(any(), any(), any())).thenReturn(elasticsearchResponseDto); - - // Call the method under test - BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = - businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields); - - assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", - businessObjectDefinitionSearchResponse, not(nullValue())); - - assertThat("The first business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME)); - - assertThat("The second business object definition name in the search response is not correct.", - businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2)); - - assertThat("The tag type code in the search response is not correct.", businessObjectDefinitionSearchResponse.getFacets().get(0).getFacetId(), - is(TAG_TYPE)); - - assertThat("The tag code in the search response is not correct.", - businessObjectDefinitionSearchResponse.getFacets().get(0).getFacets().get(0).getFacetId(), is(TAG_CODE)); - - // Verify the calls to external methods - verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class); - verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); - verify(businessObjectDefinitionIndexSearchDao).findAllBusinessObjectDefinitions(any(), any(), any()); - verifyNoMoreInteractionsHelper(); - } - - @Test - public void testUpdateSearchIndexDocumentBusinessObjectDefinitionCreate() throws Exception + public void testUpdateSearchIndexDocumentBusinessObjectDefinitionCreate() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -1092,7 +415,7 @@ public void testUpdateSearchIndexDocumentBusinessObjectDefinitionCreate() throws } @Test - public void testUpdateSearchIndexDocumentBusinessObjectDefinitionCreateEmpty() throws Exception + public void testUpdateSearchIndexDocumentBusinessObjectDefinitionCreateEmpty() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -1128,7 +451,7 @@ public void testUpdateSearchIndexDocumentBusinessObjectDefinitionCreateEmpty() t } @Test - public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUpdate() throws Exception + public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUpdate() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -1164,7 +487,7 @@ public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUpdate() throws } @Test - public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUpdateEmpty() throws Exception + public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUpdateEmpty() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -1243,7 +566,7 @@ public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUpdateIdListSiz } @Test - public void testUpdateSearchIndexDocumentBusinessObjectDefinitionDelete() throws Exception + public void testUpdateSearchIndexDocumentBusinessObjectDefinitionDelete() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -1276,7 +599,7 @@ public void testUpdateSearchIndexDocumentBusinessObjectDefinitionDelete() throws } @Test - public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUnknown() throws Exception + public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUnknown() { List businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper @@ -1308,7 +631,7 @@ public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUnknown() throw private void verifyNoMoreInteractionsHelper() { - verifyNoMoreInteractions(businessObjectDefinitionDao, businessObjectDefinitionHelper, businessObjectDefinitionIndexSearchDao, configurationDaoHelper, - configurationHelper, indexFunctionsDao, jsonHelper, tagDaoHelper, tagHelper); + verifyNoMoreInteractions(businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, indexFunctionsDao, + jsonHelper, tagDaoHelper, tagHelper); } } From 3d33024c50d4b8ff99b58fdc47b98d53275f0b28 Mon Sep 17 00:00:00 2001 From: Arthur Felde Date: Mon, 21 May 2018 17:35:33 -0400 Subject: [PATCH 03/11] DM-3103: Factory CQ - Call Cluster Mgmt without long running query - Optimize getEmrClusterDefinition query by removing table join and eliminating upper() call on namespace --- .../herd/dao/EmrClusterDefinitionDao.java | 25 +-- .../dao/impl/EmrClusterDefinitionDaoImpl.java | 73 +++----- .../org/finra/herd/dao/AbstractDaoTest.java | 4 +- .../herd/dao/EmrClusterDefinitionDaoTest.java | 144 +++++++-------- .../EmrClusterDefinitionDaoTestHelper.java | 11 +- .../helper/EmrClusterDefinitionDaoHelper.java | 60 +++++-- .../impl/EmrClusterDefinitionServiceImpl.java | 5 +- .../herd/service/impl/EmrServiceImpl.java | 73 +++----- .../EmrClusterDefinitionServiceTest.java | 16 +- .../finra/herd/service/EmrServiceTest.java | 27 +-- .../EmrClusterDefinitionDaoHelperTest.java | 167 ++++++++++++++++++ 11 files changed, 372 insertions(+), 233 deletions(-) create mode 100644 herd-code/herd-service/src/test/java/org/finra/herd/service/helper/EmrClusterDefinitionDaoHelperTest.java diff --git a/herd-code/herd-dao/src/main/java/org/finra/herd/dao/EmrClusterDefinitionDao.java b/herd-code/herd-dao/src/main/java/org/finra/herd/dao/EmrClusterDefinitionDao.java index 1acf26506f..de53a249d9 100755 --- a/herd-code/herd-dao/src/main/java/org/finra/herd/dao/EmrClusterDefinitionDao.java +++ b/herd-code/herd-dao/src/main/java/org/finra/herd/dao/EmrClusterDefinitionDao.java @@ -19,34 +19,27 @@ import org.finra.herd.model.api.xml.EmrClusterDefinitionKey; import org.finra.herd.model.jpa.EmrClusterDefinitionEntity; +import org.finra.herd.model.jpa.NamespaceEntity; public interface EmrClusterDefinitionDao extends BaseJpaDao { /** - * Retrieves EMR cluster definition entity by alternate key. + * Retrieves an EMR cluster definition entity by namespace entity and EMR cluster definition name. * - * @param emrClusterDefinitionKey the EMR cluster definition key + * @param namespaceEntity the namespace entity + * @param emrClusterDefinitionName the name of the EMR cluster definition (case-insensitive) * * @return the EMR cluster definition entity */ - public EmrClusterDefinitionEntity getEmrClusterDefinitionByAltKey(EmrClusterDefinitionKey emrClusterDefinitionKey); + EmrClusterDefinitionEntity getEmrClusterDefinitionByNamespaceAndName(NamespaceEntity namespaceEntity, String emrClusterDefinitionName); /** - * Retrieves EMR cluster definition entity by alternate key. + * Gets a list of keys for all EMR cluster definitions defined in the system for the specified namespace. The result list is sorted by EMR cluster + * definition name in ascending order. * - * @param namespace the namespace (case-insensitive) - * @param definitionName the EMR cluster definition name (case-insensitive) - * - * @return the EMR cluster definition entity - */ - public EmrClusterDefinitionEntity getEmrClusterDefinitionByAltKey(String namespace, String definitionName); - - /** - * Gets a list of keys for all EMR cluster definitions defined in the system for the specified namespace. - * - * @param namespace the namespace (case-insensitive) + * @param namespaceEntity the namespace entity * * @return the list of EMR cluster definition keys */ - public List getEmrClusterDefinitionsByNamespace(String namespace); + List getEmrClusterDefinitionKeysByNamespace(NamespaceEntity namespaceEntity); } diff --git a/herd-code/herd-dao/src/main/java/org/finra/herd/dao/impl/EmrClusterDefinitionDaoImpl.java b/herd-code/herd-dao/src/main/java/org/finra/herd/dao/impl/EmrClusterDefinitionDaoImpl.java index aeeca6a0b8..becc915ae7 100755 --- a/herd-code/herd-dao/src/main/java/org/finra/herd/dao/impl/EmrClusterDefinitionDaoImpl.java +++ b/herd-code/herd-dao/src/main/java/org/finra/herd/dao/impl/EmrClusterDefinitionDaoImpl.java @@ -18,14 +18,13 @@ import java.util.ArrayList; import java.util.List; -import javax.persistence.Tuple; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Join; import javax.persistence.criteria.Path; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import com.google.common.collect.Lists; import org.springframework.stereotype.Repository; import org.finra.herd.dao.EmrClusterDefinitionDao; @@ -33,83 +32,65 @@ import org.finra.herd.model.jpa.EmrClusterDefinitionEntity; import org.finra.herd.model.jpa.EmrClusterDefinitionEntity_; import org.finra.herd.model.jpa.NamespaceEntity; -import org.finra.herd.model.jpa.NamespaceEntity_; @Repository public class EmrClusterDefinitionDaoImpl extends AbstractHerdDao implements EmrClusterDefinitionDao { @Override - public EmrClusterDefinitionEntity getEmrClusterDefinitionByAltKey(EmrClusterDefinitionKey emrClusterDefinitionKey) + public EmrClusterDefinitionEntity getEmrClusterDefinitionByNamespaceAndName(NamespaceEntity namespaceEntity, String emrClusterDefinitionName) { - return getEmrClusterDefinitionByAltKey(emrClusterDefinitionKey.getNamespace(), emrClusterDefinitionKey.getEmrClusterDefinitionName()); - } - - @Override - public EmrClusterDefinitionEntity getEmrClusterDefinitionByAltKey(String namespaceCd, String definitionName) - { - // Create the criteria builder and the criteria. + // Create criteria builder and a top-level query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(EmrClusterDefinitionEntity.class); // The criteria root is the EMR cluster definition. - Root emrClusterDefinition = criteria.from(EmrClusterDefinitionEntity.class); - - // Join to the other tables we can filter on. - Join namespace = emrClusterDefinition.join(EmrClusterDefinitionEntity_.namespace); + Root emrClusterDefinitionEntityRoot = criteria.from(EmrClusterDefinitionEntity.class); // Create the standard restrictions (i.e. the standard where clauses). - Predicate namespaceRestriction = builder.equal(builder.upper(namespace.get(NamespaceEntity_.code)), namespaceCd.toUpperCase()); - Predicate definitionNameRestriction = - builder.equal(builder.upper(emrClusterDefinition.get(EmrClusterDefinitionEntity_.name)), definitionName.toUpperCase()); + List predicates = new ArrayList<>(); + predicates.add(builder.equal(emrClusterDefinitionEntityRoot.get(EmrClusterDefinitionEntity_.namespace), namespaceEntity)); + predicates + .add(builder.equal(builder.upper(emrClusterDefinitionEntityRoot.get(EmrClusterDefinitionEntity_.name)), emrClusterDefinitionName.toUpperCase())); - criteria.select(emrClusterDefinition).where(builder.and(namespaceRestriction, definitionNameRestriction)); + // Add all clauses for the query. + criteria.select(emrClusterDefinitionEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); + // Execute query and return result. return executeSingleResultQuery(criteria, String - .format("Found more than one EMR cluster definition with parameters {namespace=\"%s\", clusterDefinitionName=\"%s\"}.", namespace, definitionName)); + .format("Found more than one EMR cluster definition with parameters {namespace=\"%s\", emrClusterDefinitionName=\"%s\"}.", + namespaceEntity.getCode(), emrClusterDefinitionName)); } @Override - public List getEmrClusterDefinitionsByNamespace(String namespace) + public List getEmrClusterDefinitionKeysByNamespace(NamespaceEntity namespaceEntity) { - // Create the criteria builder and a tuple style criteria query. + // Create criteria builder and a top-level query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); - CriteriaQuery criteria = builder.createTupleQuery(); + CriteriaQuery criteria = builder.createQuery(String.class); // The criteria root is the EMR cluster definition. Root emrClusterDefinitionEntityRoot = criteria.from(EmrClusterDefinitionEntity.class); - // Join to the other tables we can filter on. - Join namespaceEntityJoin = emrClusterDefinitionEntityRoot.join(EmrClusterDefinitionEntity_.namespace); - - // Get the columns. - Path namespaceCodeColumn = namespaceEntityJoin.get(NamespaceEntity_.code); + // Get the EMR cluster definition name column. Path emrClusterDefinitionNameColumn = emrClusterDefinitionEntityRoot.get(EmrClusterDefinitionEntity_.name); // Create the standard restrictions (i.e. the standard where clauses). - Predicate queryRestriction = builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), namespace.toUpperCase()); - - // Add the select clause. - criteria.multiselect(namespaceCodeColumn, emrClusterDefinitionNameColumn); - - // Add the where clause. - criteria.where(queryRestriction); + Predicate predicate = builder.equal(emrClusterDefinitionEntityRoot.get(EmrClusterDefinitionEntity_.namespace), namespaceEntity); - // Add the order by clause. - criteria.orderBy(builder.asc(emrClusterDefinitionNameColumn)); + // Add all clauses for the query. + criteria.select(emrClusterDefinitionNameColumn).where(predicate).orderBy(builder.asc(emrClusterDefinitionNameColumn)); - // Run the query to get a list of tuples back. - List tuples = entityManager.createQuery(criteria).getResultList(); + // Execute the query to get a list of EMR cluster definition names back. + List emrClusterDefinitionNames = entityManager.createQuery(criteria).getResultList(); - // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row). - List emrClusterDefinitionKeys = new ArrayList<>(); - for (Tuple tuple : tuples) + // Build a list of EMR cluster definition keys. + List emrClusterDefinitionKeys = Lists.newArrayList(); + for (String emrClusterDefinitionName : emrClusterDefinitionNames) { - EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey(); - emrClusterDefinitionKeys.add(emrClusterDefinitionKey); - emrClusterDefinitionKey.setNamespace(tuple.get(namespaceCodeColumn)); - emrClusterDefinitionKey.setEmrClusterDefinitionName(tuple.get(emrClusterDefinitionNameColumn)); + emrClusterDefinitionKeys.add(new EmrClusterDefinitionKey(namespaceEntity.getCode(), emrClusterDefinitionName)); } + // Return the list of keys. return emrClusterDefinitionKeys; } } diff --git a/herd-code/herd-dao/src/test/java/org/finra/herd/dao/AbstractDaoTest.java b/herd-code/herd-dao/src/test/java/org/finra/herd/dao/AbstractDaoTest.java index 95d43e751f..c7dfbc9558 100755 --- a/herd-code/herd-dao/src/test/java/org/finra/herd/dao/AbstractDaoTest.java +++ b/herd-code/herd-dao/src/test/java/org/finra/herd/dao/AbstractDaoTest.java @@ -327,9 +327,9 @@ public abstract class AbstractDaoTest extends AbstractCoreTest public static final String EMPTY_STRING = ""; - public static final String EMR_CLUSTER_DEFINITION_NAME = "UT_EMR_CLUSTER_DFN" + RANDOM_SUFFIX; + public static final String EMR_CLUSTER_DEFINITION_NAME = "UT_EmrClusterDefinitionName_1_" + RANDOM_SUFFIX; - public static final String EMR_CLUSTER_DEFINITION_NAME_2 = "UT_EMR_CLUSTER_DFN_2" + RANDOM_SUFFIX; + public static final String EMR_CLUSTER_DEFINITION_NAME_2 = "UT_EmrClusterDefinitionName_2_" + RANDOM_SUFFIX; public static final String EMR_CLUSTER_DEFINITION_XML_FILE_MINIMAL_CLASSPATH = "classpath:testEmrClusterDefinitionMinimal.xml"; diff --git a/herd-code/herd-dao/src/test/java/org/finra/herd/dao/EmrClusterDefinitionDaoTest.java b/herd-code/herd-dao/src/test/java/org/finra/herd/dao/EmrClusterDefinitionDaoTest.java index 9bd0ce4d81..36ef7dec8a 100755 --- a/herd-code/herd-dao/src/test/java/org/finra/herd/dao/EmrClusterDefinitionDaoTest.java +++ b/herd-code/herd-dao/src/test/java/org/finra/herd/dao/EmrClusterDefinitionDaoTest.java @@ -16,13 +16,16 @@ package org.finra.herd.dao; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.List; +import com.google.common.collect.Lists; import org.apache.commons.io.IOUtils; import org.junit.Test; @@ -32,107 +35,80 @@ public class EmrClusterDefinitionDaoTest extends AbstractDaoTest { - /** - * Tests the happy path scenario by providing all the parameters. - */ @Test - public void testGetEmrClusterDefinitionByAltKey() throws IOException + public void testGetEmrClusterDefinitionByNamespaceAndName() throws IOException { - // Create and persist an EMR cluster definition entity. - emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE), EMR_CLUSTER_DEFINITION_NAME, - IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream())); - - // Call the API to query the newly added entity by providing the app and EMT cluster definition details - EmrClusterDefinitionEntity emrClusterDefinitionEntityResult = - emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME)); - - // Fail if there is any problem in the result - assertNotNull(emrClusterDefinitionEntityResult); - assertEquals(NAMESPACE, emrClusterDefinitionEntityResult.getNamespace().getCode()); - assertEquals(EMR_CLUSTER_DEFINITION_NAME, emrClusterDefinitionEntityResult.getName()); + // Create two namespace entities. + List namespaceEntities = + Arrays.asList(namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE), namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2)); + + // Create an EMR cluster definition entity for the first namespace. + EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoTestHelper + .createEmrClusterDefinitionEntity(namespaceEntities.get(0), EMR_CLUSTER_DEFINITION_NAME, + IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream(), StandardCharsets.UTF_8)); + + // Retrieve the relative EMR cluster definition entity. + assertEquals(emrClusterDefinitionEntity, + emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntities.get(0), EMR_CLUSTER_DEFINITION_NAME)); + + // Test case insensitivity of EMR cluster definition name. + assertEquals(emrClusterDefinitionEntity, + emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntities.get(0), EMR_CLUSTER_DEFINITION_NAME.toUpperCase())); + assertEquals(emrClusterDefinitionEntity, + emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntities.get(0), EMR_CLUSTER_DEFINITION_NAME.toLowerCase())); + + // Confirm that no EMR cluster definition gets selected when using wrong input parameters. + assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntities.get(1), EMR_CLUSTER_DEFINITION_NAME)); + assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntities.get(0), I_DO_NOT_EXIST)); } - /** - * Tests the scenario by providing a EMR Cluster name that doesn't exist. - */ @Test - public void testGetEmrClusterDefinitionByAltKeyDefinitionNameNoExists() throws IOException + public void testGetEmrClusterDefinitionByNamespaceAndNameMultipleRecordsFound() throws IOException { - // Create and persist an EMR Cluster definition entity. - emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE), EMR_CLUSTER_DEFINITION_NAME, - IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream())); - - // Call the API to query the newly added entity by providing the app and a definition name that doesn't exist. - EmrClusterDefinitionEntity emrClusterDefinitionEntityResult = - emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME_2); - - // Validate the results. - assertNull(emrClusterDefinitionEntityResult); - } - - /** - * Tests the scenario by providing the wrong app name. - */ - @Test - public void testGetEmrClusterDefinitionByAltKeyNamespaceNoExists() throws IOException - { - // Create namespace database entities. + // Create a namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); - namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2); - // Create a EMR Cluster definition entity - emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, - IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream())); - - // Call the API to query the newly added entity by providing the app and a definition name that doesn't exist. - EmrClusterDefinitionEntity emrClusterDefinitionEntityResult = - emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE_2, EMR_CLUSTER_DEFINITION_NAME_2); - - // Validate the results. - assertNull(emrClusterDefinitionEntityResult); - } - - /** - * Tests the scenario by finding multiple EMR Cluster definition records. - */ - @Test(expected = IllegalArgumentException.class) - public void testGetEmrClusterDefinitionByAltKeyMultipleRecordsFound() throws IOException - { - // Create namespace database entities. - NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); - - // Create two EMR cluster definitions different. - for (String definitionName : Arrays.asList(EMR_CLUSTER_DEFINITION_NAME.toUpperCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase())) + // Create two EMR cluster definitions with the same EMR cluster definition name, but with different capitalization/case. + for (String emrClusterDefinitionName : Arrays.asList(EMR_CLUSTER_DEFINITION_NAME.toUpperCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase())) { - // Create a EMR cluster definition entity. - emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, definitionName, - IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream())); + emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, emrClusterDefinitionName, + IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream(), StandardCharsets.UTF_8)); } - // Try to retrieve the the job definition. - emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME); + // Try to retrieve EMR cluster definition by namespace entity and EMR cluster definition name. + try + { + emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME); + fail(); + } + catch (IllegalArgumentException e) + { + assertEquals(String + .format("Found more than one EMR cluster definition with parameters {namespace=\"%s\", emrClusterDefinitionName=\"%s\"}.", NAMESPACE, + EMR_CLUSTER_DEFINITION_NAME), e.getMessage()); + } } @Test - public void testGetEmrClusterDefinitionsByNamespace() throws IOException + public void testGetEmrClusterDefinitionKeysByNamespace() throws IOException { - // Create and persist an EMR cluster definition entity. - emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE), EMR_CLUSTER_DEFINITION_NAME, - IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream())); + // Create two namespace entities. + List namespaceEntities = + Arrays.asList(namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE), namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2)); - // Create an EMR cluster definition key. - EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME); + // Create two EMR cluster definitions for the first namespace with EMR cluster definition names sorted in descending order. + for (String emrClusterDefinitionName : Lists.newArrayList(EMR_CLUSTER_DEFINITION_NAME_2, EMR_CLUSTER_DEFINITION_NAME)) + { + emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntities.get(0), emrClusterDefinitionName, + IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream(), StandardCharsets.UTF_8)); + } // Retrieve a list of EMR cluster definition keys. - assertEquals(Arrays.asList(emrClusterDefinitionKey), emrClusterDefinitionDao.getEmrClusterDefinitionsByNamespace(NAMESPACE)); - - // Get business object data attribute by passing namespace parameter value in uppercase. - assertEquals(Arrays.asList(emrClusterDefinitionKey), emrClusterDefinitionDao.getEmrClusterDefinitionsByNamespace(NAMESPACE.toUpperCase())); - - // Get business object data attribute by passing namespace parameter value in lowercase. - assertEquals(Arrays.asList(emrClusterDefinitionKey), emrClusterDefinitionDao.getEmrClusterDefinitionsByNamespace(NAMESPACE.toLowerCase())); + assertEquals(Lists.newArrayList(new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME), + new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME_2)), + emrClusterDefinitionDao.getEmrClusterDefinitionKeysByNamespace(namespaceEntities.get(0))); - // Try an invalid value for the namespace input parameter. - assertTrue(emrClusterDefinitionDao.getEmrClusterDefinitionsByNamespace("I_DO_NO_EXIST").isEmpty()); + // Confirm that no EMR cluster definition keys get selected when passing wrong namespace entity. + assertTrue(emrClusterDefinitionDao.getEmrClusterDefinitionKeysByNamespace(namespaceEntities.get(1)).isEmpty()); } } diff --git a/herd-code/herd-dao/src/test/java/org/finra/herd/dao/EmrClusterDefinitionDaoTestHelper.java b/herd-code/herd-dao/src/test/java/org/finra/herd/dao/EmrClusterDefinitionDaoTestHelper.java index 40dbf8f2e4..68420d068e 100644 --- a/herd-code/herd-dao/src/test/java/org/finra/herd/dao/EmrClusterDefinitionDaoTestHelper.java +++ b/herd-code/herd-dao/src/test/java/org/finra/herd/dao/EmrClusterDefinitionDaoTestHelper.java @@ -31,16 +31,17 @@ public class EmrClusterDefinitionDaoTestHelper * Creates and persists a new EMR cluster definition entity. * * @param namespaceEntity the namespace entity - * @param definitionName the cluster definition name - * @param configurationXml the cluster configuration XML + * @param emrClusterDefinitionName the EMR cluster definition name + * @param configurationXml the EMR cluster configuration XML * - * @return the newly created job definition entity + * @return the newly created EMR cluster definition entity */ - public EmrClusterDefinitionEntity createEmrClusterDefinitionEntity(NamespaceEntity namespaceEntity, String definitionName, String configurationXml) + public EmrClusterDefinitionEntity createEmrClusterDefinitionEntity(NamespaceEntity namespaceEntity, String emrClusterDefinitionName, + String configurationXml) { EmrClusterDefinitionEntity emrClusterDefinitionEntity = new EmrClusterDefinitionEntity(); emrClusterDefinitionEntity.setNamespace(namespaceEntity); - emrClusterDefinitionEntity.setName(definitionName); + emrClusterDefinitionEntity.setName(emrClusterDefinitionName); emrClusterDefinitionEntity.setConfiguration(configurationXml); return emrClusterDefinitionDao.saveAndRefresh(emrClusterDefinitionEntity); } diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/helper/EmrClusterDefinitionDaoHelper.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/helper/EmrClusterDefinitionDaoHelper.java index 440fdd2fe7..c426e8ef82 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/helper/EmrClusterDefinitionDaoHelper.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/helper/EmrClusterDefinitionDaoHelper.java @@ -15,13 +15,18 @@ */ package org.finra.herd.service.helper; +import java.util.List; + +import com.google.common.collect.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.finra.herd.dao.EmrClusterDefinitionDao; +import org.finra.herd.dao.NamespaceDao; import org.finra.herd.model.ObjectNotFoundException; import org.finra.herd.model.api.xml.EmrClusterDefinitionKey; import org.finra.herd.model.jpa.EmrClusterDefinitionEntity; +import org.finra.herd.model.jpa.NamespaceEntity; /** * Helper for EMR cluster definition related operations which require DAO. @@ -32,37 +37,62 @@ public class EmrClusterDefinitionDaoHelper @Autowired private EmrClusterDefinitionDao emrClusterDefinitionDao; + @Autowired + private NamespaceDao namespaceDao; + /** - * Gets an EMR cluster definition entity based on the key and makes sure that it exists. + * Retrieves an EMR cluster definition entity based on the EMR cluster definition key and makes sure that it exists. * * @param emrClusterDefinitionKey the EMR cluster definition key * * @return the EMR cluster definition entity - * @throws ObjectNotFoundException if the EMR cluster definition entity doesn't exist + * @throws ObjectNotFoundException if EMR cluster definition entity doesn't exist */ public EmrClusterDefinitionEntity getEmrClusterDefinitionEntity(EmrClusterDefinitionKey emrClusterDefinitionKey) throws ObjectNotFoundException { - return getEmrClusterDefinitionEntity(emrClusterDefinitionKey.getNamespace(), emrClusterDefinitionKey.getEmrClusterDefinitionName()); + EmrClusterDefinitionEntity emrClusterDefinitionEntity = null; + + // Try to retrieve the relative namespace entity. + NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(emrClusterDefinitionKey.getNamespace()); + + // If namespace entity exists, try to retrieve EMR cluster definition entity by namespace entity and EMR cluster definition name. + if (namespaceEntity != null) + { + emrClusterDefinitionEntity = + emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, emrClusterDefinitionKey.getEmrClusterDefinitionName()); + } + + // Throw an exception if EMR cluster definition entity does not exist. + if (emrClusterDefinitionEntity == null) + { + throw new ObjectNotFoundException(String + .format("EMR cluster definition with name \"%s\" doesn't exist for namespace \"%s\".", emrClusterDefinitionKey.getEmrClusterDefinitionName(), + emrClusterDefinitionKey.getNamespace())); + } + + return emrClusterDefinitionEntity; } /** - * Gets an EMR cluster definition entity based on the namespace and cluster definition name and makes sure that it exists. + * Gets a list of keys for all EMR cluster definitions defined in the system for the specified namespace. * - * @param namespace the namespace - * @param clusterDefinitionName the cluster definition name + * @param namespace the namespace (case-insensitive) * - * @return the EMR cluster definition entity - * @throws ObjectNotFoundException if the EMR cluster definition entity doesn't exist + * @return the list of EMR cluster definition keys */ - public EmrClusterDefinitionEntity getEmrClusterDefinitionEntity(String namespace, String clusterDefinitionName) throws ObjectNotFoundException + public List getEmrClusterDefinitionKeys(String namespace) { - // Get the EMR cluster definition and ensure it exists. - EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(namespace, clusterDefinitionName); - if (emrClusterDefinitionEntity == null) + // Try to retrieve the relative namespace entity. + NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace); + + // If namespace entity exists, retrieve EMR cluster definition keys by namespace entity. + if (namespaceEntity != null) { - throw new ObjectNotFoundException("EMR cluster definition with name \"" + clusterDefinitionName + "\" doesn't exist for namespace \"" + - namespace + "\"."); + return emrClusterDefinitionDao.getEmrClusterDefinitionKeysByNamespace(namespaceEntity); + } + else + { + return Lists.newArrayList(); } - return emrClusterDefinitionEntity; } } diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrClusterDefinitionServiceImpl.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrClusterDefinitionServiceImpl.java index 77489e65af..f90f44b60e 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrClusterDefinitionServiceImpl.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrClusterDefinitionServiceImpl.java @@ -88,7 +88,8 @@ public EmrClusterDefinitionInformation createEmrClusterDefinition(EmrClusterDefi request.getEmrClusterDefinition().getEc2NodeIamProfileName()); // Ensure a EMR cluster definition with the specified name doesn't already exist. - EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(request.getEmrClusterDefinitionKey()); + EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDao + .getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, request.getEmrClusterDefinitionKey().getEmrClusterDefinitionName()); if (emrClusterDefinitionEntity != null) { throw new AlreadyExistsException(String @@ -184,7 +185,7 @@ public EmrClusterDefinitionKeys getEmrClusterDefinitions(String namespace) // Retrieve and return the list of EMR cluster definition keys. EmrClusterDefinitionKeys emrClusterDefinitionKeys = new EmrClusterDefinitionKeys(); - emrClusterDefinitionKeys.getEmrClusterDefinitionKeys().addAll(emrClusterDefinitionDao.getEmrClusterDefinitionsByNamespace(namespace.trim())); + emrClusterDefinitionKeys.getEmrClusterDefinitionKeys().addAll(emrClusterDefinitionDaoHelper.getEmrClusterDefinitionKeys(namespace.trim())); return emrClusterDefinitionKeys; } diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrServiceImpl.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrServiceImpl.java index 7b54b3b4b0..2008ac5486 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrServiceImpl.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrServiceImpl.java @@ -53,6 +53,7 @@ import org.finra.herd.model.api.xml.EmrCluster; import org.finra.herd.model.api.xml.EmrClusterCreateRequest; import org.finra.herd.model.api.xml.EmrClusterDefinition; +import org.finra.herd.model.api.xml.EmrClusterDefinitionKey; import org.finra.herd.model.api.xml.EmrMasterSecurityGroup; import org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest; import org.finra.herd.model.api.xml.EmrStep; @@ -64,7 +65,6 @@ import org.finra.herd.model.dto.EmrClusterAlternateKeyDto; import org.finra.herd.model.jpa.EmrClusterCreationLogEntity; import org.finra.herd.model.jpa.EmrClusterDefinitionEntity; -import org.finra.herd.model.jpa.NamespaceEntity; import org.finra.herd.service.EmrService; import org.finra.herd.service.helper.AlternateKeyHelper; import org.finra.herd.service.helper.EmrClusterDefinitionDaoHelper; @@ -160,18 +160,14 @@ protected EmrCluster getClusterImpl(EmrClusterAlternateKeyDto emrClusterAlternat // Perform the request validation. validateEmrClusterKey(emrClusterAlternateKeyDto); - // Get the namespace and ensure it exists. - NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace()); - // Get the EMR cluster definition and ensure it exists. - EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper - .getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName()); + EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity( + new EmrClusterDefinitionKey(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName())); - EmrCluster emrCluster = - createEmrClusterFromRequest(null, namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName(), - accountId, null, null, null, null); - String clusterName = - emrHelper.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName()); + EmrCluster emrCluster = createEmrClusterFromRequest(null, emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(), + emrClusterAlternateKeyDto.getEmrClusterName(), accountId, null, null, null, null); + String clusterName = emrHelper.buildEmrClusterName(emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(), + emrClusterAlternateKeyDto.getEmrClusterName()); try { // Get Cluster status if clusterId is specified @@ -346,12 +342,9 @@ protected EmrCluster createClusterImpl(EmrClusterCreateRequest request) throws E // Perform the request validation. validateEmrClusterKey(emrClusterAlternateKeyDto); - // Get the namespace and ensure it exists. - NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace()); - // Get the EMR cluster definition and ensure it exists. - EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper - .getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName()); + EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity( + new EmrClusterDefinitionKey(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName())); // Replace all S3 managed location variables in xml String toReplace = getS3ManagedReplaceString(); @@ -392,8 +385,8 @@ protected EmrCluster createClusterImpl(EmrClusterCreateRequest request) throws E * If the cluster already exists, record the existing cluster ID. * If there is any error while attempting to check for existing cluster or create a new one, handle the exception to throw appropriate exception. */ - String clusterName = - emrHelper.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName()); + String clusterName = emrHelper.buildEmrClusterName(emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(), + emrClusterAlternateKeyDto.getEmrClusterName()); try { // Try to get an active EMR cluster by its name. @@ -433,7 +426,7 @@ protected EmrCluster createClusterImpl(EmrClusterCreateRequest request) throws E emrClusterCreated = false; } - return createEmrClusterFromRequest(clusterId, namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), + return createEmrClusterFromRequest(clusterId, emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName(), accountId, emrClusterStatus, emrClusterCreated, request.isDryRun(), emrClusterDefinition); } @@ -624,16 +617,13 @@ protected EmrCluster terminateClusterImpl(EmrClusterAlternateKeyDto emrClusterAl // Perform the request validation. validateEmrClusterKey(emrClusterAlternateKeyDto); - // Get the namespace and ensure it exists. - NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace()); - // Get the EMR cluster definition and ensure it exists. - EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper - .getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName()); + EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity( + new EmrClusterDefinitionKey(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName())); String clusterId = null; - String clusterName = - emrHelper.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName()); + String clusterName = emrHelper.buildEmrClusterName(emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(), + emrClusterAlternateKeyDto.getEmrClusterName()); try { clusterId = emrHelper.getActiveEmrClusterId(emrClusterId, clusterName, accountId); @@ -644,7 +634,7 @@ protected EmrCluster terminateClusterImpl(EmrClusterAlternateKeyDto emrClusterAl handleAmazonException(ex, "An Amazon exception occurred while terminating EMR cluster with name \"" + clusterName + "\"."); } - return createEmrClusterFromRequest(clusterId, namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), + return createEmrClusterFromRequest(clusterId, emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName(), accountId, emrDao.getEmrClusterStatusById(clusterId, awsParamsDto), null, null, null); } @@ -729,19 +719,16 @@ protected Object addStepToClusterImpl(Object request) throws Exception String accountId = stepHelper.getRequestAccountId(request); AwsParamsDto awsParamsDto = emrHelper.getAwsParamsDtoByAcccountId(accountId); - // Get the namespace and ensure it exists. - NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(stepHelper.getRequestNamespace(request)); - // Get the EMR cluster definition and ensure it exists. - EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper - .getEmrClusterDefinitionEntity(stepHelper.getRequestNamespace(request), stepHelper.getRequestEmrClusterDefinitionName(request)); + EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity( + new EmrClusterDefinitionKey(stepHelper.getRequestNamespace(request), stepHelper.getRequestEmrClusterDefinitionName(request))); // Update the namespace and cluster definition name in request from database. - stepHelper.setRequestNamespace(request, namespaceEntity.getCode()); + stepHelper.setRequestNamespace(request, emrClusterDefinitionEntity.getNamespace().getCode()); stepHelper.setRequestEmrClusterDefinitionName(request, emrClusterDefinitionEntity.getName()); - String clusterName = - emrHelper.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), stepHelper.getRequestEmrClusterName(request)); + String clusterName = emrHelper.buildEmrClusterName(emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(), + stepHelper.getRequestEmrClusterName(request)); Object emrStep = stepHelper.buildResponseFromRequest(request); try @@ -821,15 +808,13 @@ protected EmrMasterSecurityGroup addSecurityGroupsToClusterMasterImpl(EmrMasterS String accountId = request.getAccountId(); AwsParamsDto awsParamsDto = emrHelper.getAwsParamsDtoByAcccountId(accountId); - // Get the namespace and ensure it exists. - NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace()); - // Get the EMR cluster definition and ensure it exists. - EmrClusterDefinitionEntity emrClusterDefinitionEntity = - emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(request.getNamespace(), request.getEmrClusterDefinitionName()); + EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper + .getEmrClusterDefinitionEntity(new EmrClusterDefinitionKey(request.getNamespace(), request.getEmrClusterDefinitionName())); List groupIds = null; - String clusterName = emrHelper.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), request.getEmrClusterName()); + String clusterName = emrHelper + .buildEmrClusterName(emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(), request.getEmrClusterName()); try { groupIds = emrDao.addEmrMasterSecurityGroups(emrHelper.getActiveEmrClusterId(request.getEmrClusterId(), clusterName, request.getAccountId()), @@ -838,11 +823,11 @@ protected EmrMasterSecurityGroup addSecurityGroupsToClusterMasterImpl(EmrMasterS catch (AmazonServiceException ex) { handleAmazonException(ex, "An Amazon exception occurred while adding EMR security groups: " + - herdStringHelper.buildStringWithDefaultDelimiter(request.getSecurityGroupIds()) + - " to cluster: " + clusterName); + herdStringHelper.buildStringWithDefaultDelimiter(request.getSecurityGroupIds()) + " to cluster: " + clusterName); } - return createEmrClusterMasterGroupFromRequest(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), request.getEmrClusterName(), groupIds); + return createEmrClusterMasterGroupFromRequest(emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(), + request.getEmrClusterName(), groupIds); } /** diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrClusterDefinitionServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrClusterDefinitionServiceTest.java index 562305fcc0..abacf22a40 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrClusterDefinitionServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrClusterDefinitionServiceTest.java @@ -1059,7 +1059,7 @@ public void testDeleteEmrClusterDefinition() throws Exception getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH)); // Validate that this EMR cluster definition exists. - assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME)); + assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME)); executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> { // Delete this EMR cluster definition. @@ -1071,7 +1071,7 @@ public void testDeleteEmrClusterDefinition() throws Exception getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), deletedEmrClusterDefinition); // Ensure that this EMR cluster definition is no longer there. - assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME)); + assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME)); }); } @@ -1113,7 +1113,7 @@ public void testDeleteEmrClusterDefinitionTrimParameters() throws Exception getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH)); // Validate that this EMR cluster definition exists. - assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME)); + assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME)); executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> { // Delete this EMR cluster definition by passing namespace and EMR cluster definition name with leading and trailing whitespace characters. @@ -1125,7 +1125,7 @@ public void testDeleteEmrClusterDefinitionTrimParameters() throws Exception getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), deletedEmrClusterDefinition); // Ensure that this EMR cluster definition is no longer there. - assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME)); + assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME)); }); } @@ -1141,7 +1141,7 @@ public void testDeleteEmrClusterDefinitionUpperCaseParameters() throws Exception getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH)); // Validate that this EMR cluster definition exists. - assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase())); + assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME.toLowerCase())); executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> { // Delete this EMR cluster definition by passing the EMR cluster definition name key parameters in upper case. @@ -1153,7 +1153,7 @@ public void testDeleteEmrClusterDefinitionUpperCaseParameters() throws Exception getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), deletedEmrClusterDefinition); // Ensure that this EMR cluster definition is no longer there. - assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase())); + assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME.toLowerCase())); }); } @@ -1169,7 +1169,7 @@ public void testDeleteEmrClusterDefinitionLowerCaseParameters() throws Exception getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH)); // Validate that this EMR cluster definition exists. - assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE.toUpperCase(), EMR_CLUSTER_DEFINITION_NAME.toUpperCase())); + assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME.toUpperCase())); executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> { // Delete this EMR cluster definition by passing the EMR cluster definition name key parameters in lower case. @@ -1181,7 +1181,7 @@ public void testDeleteEmrClusterDefinitionLowerCaseParameters() throws Exception getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), deletedEmrClusterDefinition); // Ensure that this EMR cluster definition is no longer there. - assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE.toUpperCase(), EMR_CLUSTER_DEFINITION_NAME.toUpperCase())); + assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME.toUpperCase())); }); } diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrServiceTest.java index ce6c93cf13..04329192d2 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrServiceTest.java @@ -67,6 +67,7 @@ import org.finra.herd.model.api.xml.EmrClusterDefinitionApplication; import org.finra.herd.model.api.xml.EmrClusterDefinitionConfiguration; import org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceFleet; +import org.finra.herd.model.api.xml.EmrClusterDefinitionKey; import org.finra.herd.model.api.xml.EmrHadoopJarStep; import org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest; import org.finra.herd.model.api.xml.EmrHiveStepAddRequest; @@ -1646,7 +1647,8 @@ public void testEmrServiceMethodsNewTx() throws Exception } catch (ObjectNotFoundException e) { - assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage()); + assertEquals(String.format("EMR cluster definition with name \"%s\" doesn't exist for namespace \"%s\".", EMR_CLUSTER_DEFINITION_NAME, NAMESPACE), + e.getMessage()); } try @@ -1657,7 +1659,8 @@ public void testEmrServiceMethodsNewTx() throws Exception } catch (ObjectNotFoundException e) { - assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage()); + assertEquals(String.format("EMR cluster definition with name \"%s\" doesn't exist for namespace \"%s\".", EMR_CLUSTER_DEFINITION_NAME, NAMESPACE), + e.getMessage()); } try @@ -1668,7 +1671,8 @@ public void testEmrServiceMethodsNewTx() throws Exception } catch (ObjectNotFoundException e) { - assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage()); + assertEquals(String.format("EMR cluster definition with name \"%s\" doesn't exist for namespace \"%s\".", EMR_CLUSTER_DEFINITION_NAME, NAMESPACE), + e.getMessage()); } try @@ -1681,7 +1685,8 @@ public void testEmrServiceMethodsNewTx() throws Exception } catch (ObjectNotFoundException e) { - assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage()); + assertEquals(String.format("EMR cluster definition with name \"%s\" doesn't exist for namespace \"%s\".", EMR_CLUSTER_DEFINITION_NAME, NAMESPACE), + e.getMessage()); } try @@ -1694,7 +1699,8 @@ public void testEmrServiceMethodsNewTx() throws Exception } catch (ObjectNotFoundException e) { - assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage()); + assertEquals(String.format("EMR cluster definition with name \"%s\" doesn't exist for namespace \"%s\".", EMR_CLUSTER_DEFINITION_NAME, NAMESPACE), + e.getMessage()); } } @@ -2070,11 +2076,11 @@ public void testTerminateEmrClusterWithClusterId() throws Exception AwsParamsDto awsParamsDto = new AwsParamsDto(); when(mockEmrHelper.getAwsParamsDtoByAcccountId(any())).thenReturn(awsParamsDto); - NamespaceEntity namespaceEntity = new NamespaceEntity(); - when(mockNamespaceDaoHelper.getNamespaceEntity(any())).thenReturn(namespaceEntity); + NamespaceEntity namespaceEntity = new NamespaceEntity(); EmrClusterDefinitionEntity emrClusterDefinitionEntity = new EmrClusterDefinitionEntity(); - when(mockEmrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(any(), any())).thenReturn(emrClusterDefinitionEntity); + emrClusterDefinitionEntity.setNamespace(namespaceEntity); + when(mockEmrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(any())).thenReturn(emrClusterDefinitionEntity); String buildEmrClusterNameResult = "buildEmrClusterNameResult"; when(mockEmrHelper.buildEmrClusterName(any(), any(), any())).thenReturn(buildEmrClusterNameResult); @@ -2088,9 +2094,8 @@ public void testTerminateEmrClusterWithClusterId() throws Exception verify(mockAlternateKeyHelper).validateStringParameter("namespace", namespace); verify(mockAlternateKeyHelper).validateStringParameter("An", "EMR cluster definition name", emrClusterDefinitionName); verify(mockAlternateKeyHelper).validateStringParameter("An", "EMR cluster name", emrClusterName); - verify(mockNamespaceDaoHelper).getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace()); - verify(mockEmrClusterDefinitionDaoHelper) - .getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName()); + verify(mockEmrClusterDefinitionDaoHelper).getEmrClusterDefinitionEntity( + new EmrClusterDefinitionKey(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName())); verify(mockEmrHelper) .buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName()); verify(mockEmrHelper).getActiveEmrClusterId(emrClusterId, buildEmrClusterNameResult, null); diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/helper/EmrClusterDefinitionDaoHelperTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/helper/EmrClusterDefinitionDaoHelperTest.java new file mode 100644 index 0000000000..59921f422d --- /dev/null +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/helper/EmrClusterDefinitionDaoHelperTest.java @@ -0,0 +1,167 @@ +/* +* Copyright 2015 herd contributors +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.finra.herd.service.helper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +import java.util.List; + +import com.google.common.collect.Lists; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import org.finra.herd.dao.EmrClusterDefinitionDao; +import org.finra.herd.dao.NamespaceDao; +import org.finra.herd.model.ObjectNotFoundException; +import org.finra.herd.model.api.xml.EmrClusterDefinitionKey; +import org.finra.herd.model.jpa.EmrClusterDefinitionEntity; +import org.finra.herd.model.jpa.NamespaceEntity; +import org.finra.herd.service.AbstractServiceTest; + +/** + * This class tests functionality within the EMR cluster definition DAO helper. + */ +public class EmrClusterDefinitionDaoHelperTest extends AbstractServiceTest +{ + @Mock + private EmrClusterDefinitionDao emrClusterDefinitionDao; + + @InjectMocks + private EmrClusterDefinitionDaoHelper emrClusterDefinitionDaoHelper; + + @Mock + private NamespaceDao namespaceDao; + + @Before + public void before() + { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testGetEmrClusterDefinitionEntity() + { + // Create a namespace entity. + NamespaceEntity namespaceEntity = new NamespaceEntity(); + + // Create an EMR cluster definition entity. + EmrClusterDefinitionEntity emrClusterDefinitionEntity = new EmrClusterDefinitionEntity(); + + // Create an EMR cluster definition key. + EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME); + + // Mock the external calls. + when(namespaceDao.getNamespaceByCd(NAMESPACE)).thenReturn(namespaceEntity); + when(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME)) + .thenReturn(emrClusterDefinitionEntity); + + // Call the method under test. + EmrClusterDefinitionEntity result = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey); + + // Verify the external calls. + verify(namespaceDao).getNamespaceByCd(NAMESPACE); + verify(emrClusterDefinitionDao).getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME); + verifyNoMoreInteractionsHelper(); + + // Validate the result. + assertEquals(emrClusterDefinitionEntity, result); + } + + @Test + public void testGetEmrClusterDefinitionEntityNamespaceNoExists() + { + // Create an EMR cluster definition key. + EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME); + + // Mock the external calls. + when(namespaceDao.getNamespaceByCd(NAMESPACE)).thenReturn(null); + + // Try to call the method under test. + try + { + emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey); + fail(); + } + catch (ObjectNotFoundException e) + { + assertEquals(String.format("EMR cluster definition with name \"%s\" doesn't exist for namespace \"%s\".", EMR_CLUSTER_DEFINITION_NAME, NAMESPACE), + e.getMessage()); + } + + // Verify the external calls. + verify(namespaceDao).getNamespaceByCd(NAMESPACE); + verifyNoMoreInteractionsHelper(); + } + + @Test + public void testGetEmrClusterDefinitionKeys() + { + // Create a namespace entity. + NamespaceEntity namespaceEntity = new NamespaceEntity(); + + // Create a list of EMR cluster definition keys. + List emrClusterDefinitionKeys = Lists.newArrayList(new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME)); + + // Mock the external calls. + when(namespaceDao.getNamespaceByCd(NAMESPACE)).thenReturn(namespaceEntity); + when(emrClusterDefinitionDao.getEmrClusterDefinitionKeysByNamespace(namespaceEntity)).thenReturn(emrClusterDefinitionKeys); + + // Call the method under test. + List result = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionKeys(NAMESPACE); + + // Verify the external calls. + verify(namespaceDao).getNamespaceByCd(NAMESPACE); + verify(emrClusterDefinitionDao).getEmrClusterDefinitionKeysByNamespace(namespaceEntity); + verifyNoMoreInteractionsHelper(); + + // Validate the result. + assertEquals(emrClusterDefinitionKeys, result); + } + + @Test + public void testGetEmrClusterDefinitionKeysNamespaceNoExists() + { + // Mock the external calls. + when(namespaceDao.getNamespaceByCd(NAMESPACE)).thenReturn(null); + + // Call the method under test. + List result = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionKeys(NAMESPACE); + + // Verify the external calls. + verify(namespaceDao).getNamespaceByCd(NAMESPACE); + verifyNoMoreInteractionsHelper(); + + // Validate the result. + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Checks if any of the mocks has any interaction. + */ + private void verifyNoMoreInteractionsHelper() + { + verifyNoMoreInteractions(emrClusterDefinitionDao, namespaceDao); + } +} From ac2917fe041878a99119e9315dba6ee2fcbb72bf Mon Sep 17 00:00:00 2001 From: Mona Annaparthi Date: Wed, 23 May 2018 12:16:00 -0400 Subject: [PATCH 04/11] DM-10653 ( Allow non-backwards compatible Schema changes based on Format indicator) - initial commit ( added controller and a abstract service ) --- .../src/main/resources/herd.xsd | 25 ++++++++++++- .../herd/model/dto/SecurityFunctions.java | 6 ++-- .../BusinessObjectFormatRestController.java | 28 +++++++++++++++ ...usinessObjectFormatRestControllerTest.java | 35 ++++++++++++++++--- .../service/BusinessObjectFormatService.java | 10 ++++++ .../impl/BusinessObjectFormatServiceImpl.java | 20 +++++++++-- .../herd/service/AbstractServiceTest.java | 2 ++ ...nalTableRegistrationHelperServiceTest.java | 3 +- 8 files changed, 119 insertions(+), 10 deletions(-) diff --git a/herd-code/herd-model-api/src/main/resources/herd.xsd b/herd-code/herd-model-api/src/main/resources/herd.xsd index eed6a4d05f..abfa1b71cd 100755 --- a/herd-code/herd-model-api/src/main/resources/herd.xsd +++ b/herd-code/herd-model-api/src/main/resources/herd.xsd @@ -2144,6 +2144,23 @@ + + + + + + + If true,allows non backwards compatible changes to the schema. + + + + + + @@ -2248,7 +2265,13 @@ - Retention type. Supported retention types: PARTITION_VALUE + Retention type. Supported retention types: PARTITION_VALUE , BDATA_RETENTION_TYPE. + + + + + + If true,allows non backwards compatible changes to the schema. diff --git a/herd-code/herd-model/src/main/java/org/finra/herd/model/dto/SecurityFunctions.java b/herd-code/herd-model/src/main/java/org/finra/herd/model/dto/SecurityFunctions.java index b74e087558..00b468512b 100755 --- a/herd-code/herd-model/src/main/java/org/finra/herd/model/dto/SecurityFunctions.java +++ b/herd-code/herd-model/src/main/java/org/finra/herd/model/dto/SecurityFunctions.java @@ -144,8 +144,7 @@ public class SecurityFunctions public static final String FN_BUSINESS_OBJECT_DEFINITION_COLUMNS_SEARCH_POST = "FN_BUSINESS_OBJECT_DEFINITION_COLUMNS_SEARCH_POST"; - public static final String FN_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTIONS_ALL_GET = - "FN_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTIONS_ALL_GET"; + public static final String FN_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTIONS_ALL_GET = "FN_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTIONS_ALL_GET"; public static final String FN_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTIONS_DELETE = "FN_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTIONS_DELETE"; @@ -193,6 +192,9 @@ public class SecurityFunctions public static final String FN_BUSINESS_OBJECT_FORMAT_RETENTION_INFORMATION_PUT = "FN_BUSINESS_OBJECT_FORMAT_RETENTION_INFORMATION_PUT"; + public static final String FN_BUSINESS_OBJECT_FORMAT_SCHEMA_BACKWARDS_COMPATIBILITY_PUT = + "FN_BUSINESS_OBJECT_FORMAT_SCHEMA_BACKWARDS_COMPATIBILITY_PUT"; + public static final String FN_CUSTOM_DDLS_ALL_GET = "FN_CUSTOM_DDLS_ALL_GET"; public static final String FN_CUSTOM_DDLS_DELETE = "FN_CUSTOM_DDLS_DELETE"; diff --git a/herd-code/herd-rest/src/main/java/org/finra/herd/rest/BusinessObjectFormatRestController.java b/herd-code/herd-rest/src/main/java/org/finra/herd/rest/BusinessObjectFormatRestController.java index 724763f77e..7c905d223d 100755 --- a/herd-code/herd-rest/src/main/java/org/finra/herd/rest/BusinessObjectFormatRestController.java +++ b/herd-code/herd-rest/src/main/java/org/finra/herd/rest/BusinessObjectFormatRestController.java @@ -39,6 +39,7 @@ import org.finra.herd.model.api.xml.BusinessObjectFormatKeys; import org.finra.herd.model.api.xml.BusinessObjectFormatParentsUpdateRequest; import org.finra.herd.model.api.xml.BusinessObjectFormatRetentionInformationUpdateRequest; +import org.finra.herd.model.api.xml.BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest; import org.finra.herd.model.api.xml.BusinessObjectFormatUpdateRequest; import org.finra.herd.model.dto.SecurityFunctions; import org.finra.herd.service.BusinessObjectFormatService; @@ -330,4 +331,31 @@ public BusinessObjectFormat updateBusinessObjectFormatRetentionInformation(@Path new BusinessObjectFormatKey(namespace, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, null); return businessObjectFormatService.updateBusinessObjectFormatRetentionInformation(businessObjectFormatKey, request); } + + /** + * Updates an existing Business Object Format to allow non-backwards compatibility changes to the format schema based on the + * 'allowNonBackwardsCompatibleChanges' flag.

Requires WRITE permission on namespace

+ * + * @param namespace the namespace code + * @param businessObjectDefinitionName the business object definition name + * @param businessObjectFormatUsage the business object format usage + * @param businessObjectFormatFileType the business object format file type + * @param request the information needed to update the business object format to allow non-backwards compatibility changes to the format schema + * + * @return the updated business object format. + */ + @RequestMapping(value = "/businessObjectFormatSchemaBackwardsCompatibility/namespaces/{namespace}/businessObjectDefinitionNames/" + + "{businessObjectDefinitionName}/businessObjectFormatUsages/{businessObjectFormatUsage}/businessObjectFormatFileTypes/{businessObjectFormatFileType}", + method = RequestMethod.PUT, consumes = {"application/xml", "application/json"}) + @Secured(SecurityFunctions.FN_BUSINESS_OBJECT_FORMAT_SCHEMA_BACKWARDS_COMPATIBILITY_PUT) + public BusinessObjectFormat updateBusinessObjectFormatSchemaBackwardsCompatibleChanges(@PathVariable("namespace") String namespace, + @PathVariable("businessObjectDefinitionName") String businessObjectDefinitionName, + @PathVariable("businessObjectFormatUsage") String businessObjectFormatUsage, + @PathVariable("businessObjectFormatFileType") String businessObjectFormatFileType, + @RequestBody BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest request) + { + BusinessObjectFormatKey businessObjectFormatKey = + new BusinessObjectFormatKey(namespace, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, null); + return businessObjectFormatService.updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(businessObjectFormatKey, request); + } } diff --git a/herd-code/herd-rest/src/test/java/org/finra/herd/rest/BusinessObjectFormatRestControllerTest.java b/herd-code/herd-rest/src/test/java/org/finra/herd/rest/BusinessObjectFormatRestControllerTest.java index 4246a14e6e..f29c8ede45 100755 --- a/herd-code/herd-rest/src/test/java/org/finra/herd/rest/BusinessObjectFormatRestControllerTest.java +++ b/herd-code/herd-rest/src/test/java/org/finra/herd/rest/BusinessObjectFormatRestControllerTest.java @@ -44,6 +44,7 @@ import org.finra.herd.model.api.xml.BusinessObjectFormatKeys; import org.finra.herd.model.api.xml.BusinessObjectFormatParentsUpdateRequest; import org.finra.herd.model.api.xml.BusinessObjectFormatRetentionInformationUpdateRequest; +import org.finra.herd.model.api.xml.BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest; import org.finra.herd.model.api.xml.BusinessObjectFormatUpdateRequest; import org.finra.herd.model.jpa.FileTypeEntity; import org.finra.herd.model.jpa.RetentionTypeEntity; @@ -81,7 +82,8 @@ public void testCreateBusinessObjectFormat() BusinessObjectFormat businessObjectFormat = new BusinessObjectFormat(ID, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 0, true, PARTITION_KEY, FORMAT_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), - businessObjectFormatServiceTestHelper.getTestSchema(), null, null, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE); + businessObjectFormatServiceTestHelper.getTestSchema(), null, null, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE, + NO_ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET); when(businessObjectFormatService.createBusinessObjectFormat(request)).thenReturn(businessObjectFormat); BusinessObjectFormat resultBusinessObjectFormat = businessObjectFormatRestController.createBusinessObjectFormat(request); @@ -99,7 +101,8 @@ public void testDeleteBusinessObjectFormat() throws Exception BusinessObjectFormat businessObjectFormat = new BusinessObjectFormat(ID, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, true, PARTITION_KEY, FORMAT_DESCRIPTION, NO_ATTRIBUTES, businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), - businessObjectFormatServiceTestHelper.getTestSchema(), null, null, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE); + businessObjectFormatServiceTestHelper.getTestSchema(), null, null, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE, + NO_ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET); BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION); @@ -171,7 +174,8 @@ public void testGetBusinessObjectFormat() BusinessObjectFormat businessObjectFormat = new BusinessObjectFormat(ID, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, true, PARTITION_KEY, FORMAT_DESCRIPTION, NO_ATTRIBUTES, businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), - businessObjectFormatServiceTestHelper.getTestSchema(), null, null, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE); + businessObjectFormatServiceTestHelper.getTestSchema(), null, null, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE, + NO_ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET); BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION); @@ -235,7 +239,7 @@ public void testUpdateBusinessObjectFormat() BusinessObjectFormat businessObjectFormat = new BusinessObjectFormat(ID, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 1, true, PARTITION_KEY, FORMAT_DESCRIPTION_2, NO_ATTRIBUTES, businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), businessObjectFormatServiceTestHelper.getTestSchema2(), - null, null, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE); + null, null, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE, NO_ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET); BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION); @@ -350,4 +354,27 @@ public void testUpdateBusinessObjectFormatRetentionInformation() // Validate the returned object. assertEquals(businessObjectFormat, updatedBusinessObjectFormat); } + + @Test + public void testUpdateBusinessObjectFormatSchemaCompatibleChanges() + { + BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null); + BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest updateRequest = new BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest(); + updateRequest.setAllowNonBackwardsCompatibleChanges(true); + + BusinessObjectFormat businessObjectFormat = new BusinessObjectFormat(); + when(businessObjectFormatService.updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(businessObjectFormatKey, updateRequest)) + .thenReturn(businessObjectFormat); + + BusinessObjectFormat updatedBusinessObjectFormat = businessObjectFormatRestController + .updateBusinessObjectFormatSchemaBackwardsCompatibleChanges(businessObjectFormatKey.getNamespace(), + businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), + businessObjectFormatKey.getBusinessObjectFormatFileType(), updateRequest); + + // Verify the external calls. + verify(businessObjectFormatService).updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(businessObjectFormatKey, updateRequest); + verifyNoMoreInteractions(businessObjectFormatService); + // Validate the returned object. + assertEquals(businessObjectFormat, updatedBusinessObjectFormat); + } } diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectFormatService.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectFormatService.java index 5e13aa1c9f..f188d7369c 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectFormatService.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectFormatService.java @@ -28,6 +28,7 @@ import org.finra.herd.model.api.xml.BusinessObjectFormatKeys; import org.finra.herd.model.api.xml.BusinessObjectFormatParentsUpdateRequest; import org.finra.herd.model.api.xml.BusinessObjectFormatRetentionInformationUpdateRequest; +import org.finra.herd.model.api.xml.BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest; import org.finra.herd.model.api.xml.BusinessObjectFormatUpdateRequest; /** @@ -158,4 +159,13 @@ public BusinessObjectFormat updateBusinessObjectFormatAttributeDefinitions(Busin */ public BusinessObjectFormat updateBusinessObjectFormatRetentionInformation(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatRetentionInformationUpdateRequest businessObjectFormatRetentionInformationUpdateRequest); + + /** + * Update business object format schema backwards compatible changes + * @param businessObjectFormatKey the business object format alternate key + * @param businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest business object format schema backwards compatible changes update request + * @return updated business object format + */ + public BusinessObjectFormat updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(BusinessObjectFormatKey businessObjectFormatKey, + BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest); } diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java index f7dc0fbb3b..6577613878 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java @@ -61,6 +61,7 @@ import org.finra.herd.model.api.xml.BusinessObjectFormatKeys; import org.finra.herd.model.api.xml.BusinessObjectFormatParentsUpdateRequest; import org.finra.herd.model.api.xml.BusinessObjectFormatRetentionInformationUpdateRequest; +import org.finra.herd.model.api.xml.BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest; import org.finra.herd.model.api.xml.BusinessObjectFormatUpdateRequest; import org.finra.herd.model.api.xml.CustomDdlKey; import org.finra.herd.model.api.xml.NamespacePermissionEnum; @@ -478,8 +479,7 @@ public BusinessObjectFormatDdlCollectionResponse generateBusinessObjectFormatDdl } @NamespacePermissions({@NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE), - @NamespacePermission(fields = "#businessObjectFormatParentsUpdateRequest?.businessObjectFormatParents?.![namespace]", - permissions = NamespacePermissionEnum.READ)}) + @NamespacePermission(fields = "#businessObjectFormatParentsUpdateRequest?.businessObjectFormatParents?.![namespace]", permissions = NamespacePermissionEnum.READ)}) @Override public BusinessObjectFormat updateBusinessObjectFormatParents(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatParentsUpdateRequest businessObjectFormatParentsUpdateRequest) @@ -723,6 +723,22 @@ public BusinessObjectFormat updateBusinessObjectFormatRetentionInformation(Busin return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity); } + @NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE) + @Override + public BusinessObjectFormat updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(BusinessObjectFormatKey businessObjectFormatKey, + BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest) + { + // Validate and trim the business object format schema backwards compatibility changes update request. + Assert.notNull(businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest, + "A business object format schema backwards compatibility changes update request must be specified."); + Assert.notNull(businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest.isAllowNonBackwardsCompatibleChanges(), + "allowNonBackwardsCompatibleChanges flag in business object format schema backwards compatibility changes update request must be specified."); + businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey, false); + Assert.isNull(businessObjectFormatKey.getBusinessObjectFormatVersion(), "Business object format version must not be specified."); + + return null; + } + /** * Validates the business object format create request, except for the alternate key values. This method also trims request parameters. * diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java index 8a7478589e..5b087d8789 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java @@ -554,6 +554,8 @@ public abstract class AbstractServiceTest extends AbstractDaoTest public static final String NO_RETENTION_TYPE = null; + public static final Boolean NO_ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET = null; + public static final Long NO_ROW_COUNT = null; public static final SearchIndexStatistics NO_SEARCH_INDEX_STATISTICS = null; diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/RelationalTableRegistrationHelperServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/RelationalTableRegistrationHelperServiceTest.java index d06119822c..41873f37a4 100644 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/RelationalTableRegistrationHelperServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/RelationalTableRegistrationHelperServiceTest.java @@ -334,7 +334,8 @@ public void testRelationalTableRegistrationHelperServiceMethodsNewTransactionPro SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), new RelationalStorageAttributesDto(), RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME, new BusinessObjectFormat(ID, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, DESCRIPTION, NO_ATTRIBUTES, NO_ATTRIBUTE_DEFINITIONS, NO_SCHEMA, NO_BUSINESS_OBJECT_FORMAT_PARENTS, - NO_BUSINESS_OBJECT_FORMAT_CHILDREN, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE)), NO_COLUMNS); + NO_BUSINESS_OBJECT_FORMAT_CHILDREN, NO_RECORD_FLAG_SET, NO_RETENTION_PERIOD_IN_DAYS, NO_RETENTION_TYPE, + NO_ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET)), NO_COLUMNS); fail(); } catch (IllegalArgumentException e) From 4ada70fa8f86a22854e0306ef2706306afb96a2a Mon Sep 17 00:00:00 2001 From: Mona Annaparthi Date: Wed, 23 May 2018 13:22:05 -0400 Subject: [PATCH 05/11] DM-10653 ( Allow non-backwards compatible Schema changes based on Format indicator) - formatted code --- herd-code/herd-model-api/src/main/resources/herd.xsd | 2 +- .../finra/herd/service/BusinessObjectFormatService.java | 8 ++++++-- .../service/impl/BusinessObjectFormatServiceImpl.java | 3 ++- .../java/org/finra/herd/service/AbstractServiceTest.java | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/herd-code/herd-model-api/src/main/resources/herd.xsd b/herd-code/herd-model-api/src/main/resources/herd.xsd index abfa1b71cd..94fd161e5c 100755 --- a/herd-code/herd-model-api/src/main/resources/herd.xsd +++ b/herd-code/herd-model-api/src/main/resources/herd.xsd @@ -2154,7 +2154,7 @@ the field as null. The validation that this field is required is handled via the service layer validation. --> - If true,allows non backwards compatible changes to the schema. + If true,allows non backwards compatible changes to the schema
diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectFormatService.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectFormatService.java index f188d7369c..bacfa11015 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectFormatService.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/BusinessObjectFormatService.java @@ -152,18 +152,22 @@ public BusinessObjectFormat updateBusinessObjectFormatAttributeDefinitions(Busin BusinessObjectFormatAttributeDefinitionsUpdateRequest businessObjectFormatAttributeDefinitionsUpdateRequest); /** - * Update business object format retention information + * Updates business object format retention information + * * @param businessObjectFormatKey the business object format alternate key * @param businessObjectFormatRetentionInformationUpdateRequest business object format retention information update request + * * @return updated business object format */ public BusinessObjectFormat updateBusinessObjectFormatRetentionInformation(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatRetentionInformationUpdateRequest businessObjectFormatRetentionInformationUpdateRequest); /** - * Update business object format schema backwards compatible changes + * Updates business object format schema backwards compatible changes + * * @param businessObjectFormatKey the business object format alternate key * @param businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest business object format schema backwards compatible changes update request + * * @return updated business object format */ public BusinessObjectFormat updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(BusinessObjectFormatKey businessObjectFormatKey, diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java index 6577613878..88e0631763 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java @@ -479,7 +479,8 @@ public BusinessObjectFormatDdlCollectionResponse generateBusinessObjectFormatDdl } @NamespacePermissions({@NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE), - @NamespacePermission(fields = "#businessObjectFormatParentsUpdateRequest?.businessObjectFormatParents?.![namespace]", permissions = NamespacePermissionEnum.READ)}) + @NamespacePermission(fields = "#businessObjectFormatParentsUpdateRequest?.businessObjectFormatParents?.![namespace]", + permissions = NamespacePermissionEnum.READ)}) @Override public BusinessObjectFormat updateBusinessObjectFormatParents(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatParentsUpdateRequest businessObjectFormatParentsUpdateRequest) diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java index 5b087d8789..771f3188ab 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java @@ -554,7 +554,7 @@ public abstract class AbstractServiceTest extends AbstractDaoTest public static final String NO_RETENTION_TYPE = null; - public static final Boolean NO_ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET = null; + public static final Boolean NO_ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET = false; public static final Long NO_ROW_COUNT = null; From b4de0e15e7aea06d954f8e80923026a63494640d Mon Sep 17 00:00:00 2001 From: Mona Annaparthi Date: Wed, 23 May 2018 14:02:08 -0400 Subject: [PATCH 06/11] DM-10653 ( Allow non-backwards compatible Schema changes based on Format indicator) - formatted code --- herd-code/herd-model-api/src/main/resources/herd.xsd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/herd-code/herd-model-api/src/main/resources/herd.xsd b/herd-code/herd-model-api/src/main/resources/herd.xsd index 94fd161e5c..082de2ab32 100755 --- a/herd-code/herd-model-api/src/main/resources/herd.xsd +++ b/herd-code/herd-model-api/src/main/resources/herd.xsd @@ -2154,7 +2154,7 @@ the field as null. The validation that this field is required is handled via the service layer validation. --> - If true,allows non backwards compatible changes to the schema + If true, allows non backwards compatible changes to the schema
@@ -2265,13 +2265,13 @@ - Retention type. Supported retention types: PARTITION_VALUE , BDATA_RETENTION_TYPE. + Retention type. Supported retention types: PARTITION_VALUE, BDATA_RETENTION_TYPE. - If true,allows non backwards compatible changes to the schema. + If true, allows non backwards compatible changes to the schema From 64a369a26b1b4adb511ab88c2f21141b16f8e95c Mon Sep 17 00:00:00 2001 From: Arthur Felde Date: Wed, 23 May 2018 16:06:56 -0400 Subject: [PATCH 07/11] DM-10834: Support for Kerberos Attributes in EMR Cluster Definition - Add kerberosAttributes element to the emrClusterDefinition model object --- .../org/finra/herd/dao/impl/EmrDaoImpl.java | 29 +++++++++++++++ .../org/finra/herd/dao/AbstractDaoTest.java | 10 +++++ .../java/org/finra/herd/dao/EmrDaoTest.java | 8 ++++ .../resources/testEmrClusterDefinition.xml | 9 ++++- .../src/main/resources/herd.xsd | 37 +++++++++++++++++++ .../herd/service/impl/EmrServiceImpl.java | 4 ++ .../finra/herd/service/EmrServiceTest.java | 7 ++++ pom.xml | 2 +- 8 files changed, 104 insertions(+), 2 deletions(-) diff --git a/herd-code/herd-dao/src/main/java/org/finra/herd/dao/impl/EmrDaoImpl.java b/herd-code/herd-dao/src/main/java/org/finra/herd/dao/impl/EmrDaoImpl.java index 369974a7b8..c0162e292b 100755 --- a/herd-code/herd-dao/src/main/java/org/finra/herd/dao/impl/EmrDaoImpl.java +++ b/herd-code/herd-dao/src/main/java/org/finra/herd/dao/impl/EmrDaoImpl.java @@ -42,6 +42,7 @@ import com.amazonaws.services.elasticmapreduce.model.InstanceRoleType; import com.amazonaws.services.elasticmapreduce.model.InstanceTypeConfig; import com.amazonaws.services.elasticmapreduce.model.JobFlowInstancesConfig; +import com.amazonaws.services.elasticmapreduce.model.KerberosAttributes; import com.amazonaws.services.elasticmapreduce.model.ListClustersRequest; import com.amazonaws.services.elasticmapreduce.model.ListClustersResult; import com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsRequest; @@ -83,6 +84,7 @@ import org.finra.herd.model.api.xml.EmrClusterDefinitionEbsConfiguration; import org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceFleet; import org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceTypeConfig; +import org.finra.herd.model.api.xml.EmrClusterDefinitionKerberosAttributes; import org.finra.herd.model.api.xml.EmrClusterDefinitionLaunchSpecifications; import org.finra.herd.model.api.xml.EmrClusterDefinitionSpotSpecification; import org.finra.herd.model.api.xml.EmrClusterDefinitionVolumeSpecification; @@ -544,6 +546,30 @@ protected List getInstanceTypeConfigs(List() @@ -625,6 +630,9 @@ public String answer(InvocationOnMock invocation) throws Throwable assertEquals("scaleDownBehavior", runJobFlowRequest.getScaleDownBehavior()); assertEquals(EMR_MASTER_SECURITY_GROUP, runJobFlowRequest.getInstances().getEmrManagedMasterSecurityGroup()); assertEquals(EMR_SLAVE_SECURITY_GROUP, runJobFlowRequest.getInstances().getEmrManagedSlaveSecurityGroup()); + assertEquals(new KerberosAttributes().withADDomainJoinPassword(AD_DOMAIN_JOIN_PASSWORD).withADDomainJoinUser(AD_DOMAIN_JOIN_USER) + .withCrossRealmTrustPrincipalPassword(CROSS_REALM_TRUST_PRINCIPAL_PASSWORD).withKdcAdminPassword(KDC_ADMIN_PASSWORD).withRealm(REALM), + runJobFlowRequest.getKerberosAttributes()); return clusterId; } }); diff --git a/herd-code/herd-dao/src/test/resources/testEmrClusterDefinition.xml b/herd-code/herd-dao/src/test/resources/testEmrClusterDefinition.xml index 4a27c5c651..9d9e712ed0 100755 --- a/herd-code/herd-dao/src/test/resources/testEmrClusterDefinition.xml +++ b/herd-code/herd-dao/src/test/resources/testEmrClusterDefinition.xml @@ -146,4 +146,11 @@ additionalSlaveSecurityGroup scaleDownBehavior - \ No newline at end of file + + aDDomainJoinPassword + aDDomainJoinUser + crossRealmTrustPrincipalPassword + kdcAdminPassword + realm + + diff --git a/herd-code/herd-model-api/src/main/resources/herd.xsd b/herd-code/herd-model-api/src/main/resources/herd.xsd index 082de2ab32..986b21f805 100755 --- a/herd-code/herd-model-api/src/main/resources/herd.xsd +++ b/herd-code/herd-model-api/src/main/resources/herd.xsd @@ -5600,6 +5600,11 @@ + + + Attributes for Kerberos configuration when Kerberos authentication is enabled using a security configuration + + @@ -6450,6 +6455,38 @@ + + + + + The Active Directory password for ADDomainJoinUser + + + + + Required only when establishing a cross-realm trust with an Active Directory domain + + + + + Required only when establishing a cross-realm trust with a KDC in a different realm + + + + + The password used within the cluster for the kadmin service on the cluster-dedicated KDC, which maintains Kerberos principals, + password policies, and keytabs for the cluster + + + + + + The name of the Kerberos realm to which all nodes in a cluster belong + + + + + diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrServiceImpl.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrServiceImpl.java index 2008ac5486..fb54f19342 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrServiceImpl.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/EmrServiceImpl.java @@ -581,6 +581,10 @@ private void overrideEmrClusterDefinition(EmrClusterDefinition emrClusterDefinit { emrClusterDefinition.setScaleDownBehavior(emrClusterDefinitionOverride.getScaleDownBehavior()); } + if (emrClusterDefinitionOverride.getKerberosAttributes() != null) + { + emrClusterDefinition.setKerberosAttributes(emrClusterDefinitionOverride.getKerberosAttributes()); + } } } diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrServiceTest.java index 04329192d2..e41230dc43 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/EmrServiceTest.java @@ -67,6 +67,7 @@ import org.finra.herd.model.api.xml.EmrClusterDefinitionApplication; import org.finra.herd.model.api.xml.EmrClusterDefinitionConfiguration; import org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceFleet; +import org.finra.herd.model.api.xml.EmrClusterDefinitionKerberosAttributes; import org.finra.herd.model.api.xml.EmrClusterDefinitionKey; import org.finra.herd.model.api.xml.EmrHadoopJarStep; import org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest; @@ -235,6 +236,7 @@ public void testCreateEmrCluster() throws Exception String definitionXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()); EmrClusterDefinition expectedEmrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, definitionXml); assertEquals("scaleDownBehavior", expectedEmrClusterDefinition.getScaleDownBehavior()); + assertNotNull(expectedEmrClusterDefinition.getKerberosAttributes()); emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, definitionXml); // Create a new EMR cluster create request @@ -374,6 +376,7 @@ public void testCreateEmrClusterBlankParams() throws Exception emrClusterDefinition.setAmiVersion(null); emrClusterDefinition.setServiceIamRole(emrClusterDefinition.getEc2NodeIamProfileName()); emrClusterDefinition.setScaleDownBehavior(null); + emrClusterDefinition.setKerberosAttributes(null); configXml = xmlHelper.objectToXml(emrClusterDefinition); @@ -1024,6 +1027,10 @@ public void testCreateEmrClusterOverrideScalar() throws Exception expectedEmrClusterDefinition.setTerminationProtection(emrClusterDefinitionOverride.isTerminationProtection()); emrClusterDefinitionOverride.setVisibleToAll(!expectedEmrClusterDefinition.isVisibleToAll()); expectedEmrClusterDefinition.setVisibleToAll(emrClusterDefinitionOverride.isVisibleToAll()); + emrClusterDefinitionOverride.setKerberosAttributes( + new EmrClusterDefinitionKerberosAttributes("test" + Math.random(), "test" + Math.random(), "test" + Math.random(), "test" + Math.random(), + "test" + Math.random())); + expectedEmrClusterDefinition.setKerberosAttributes(emrClusterDefinitionOverride.getKerberosAttributes()); request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride); EmrCluster emrCluster = emrService.createCluster(request); diff --git a/pom.xml b/pom.xml index 494cf136f3..e12fef9efa 100755 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ --> 5.19.0.1 1.8.11 - 1.11.210 + 1.11.333 1.0.4 2.1.1 1.4 From 74ee4aac4f03280c0fcd39c92eb039c7de565073 Mon Sep 17 00:00:00 2001 From: K26992 Date: Fri, 25 May 2018 10:49:07 -0400 Subject: [PATCH 08/11] DM-10653 ( Allow non-backwards compatible Schema changes based on Format indicator) - added business logic - added unit tests --- .../model/jpa/BusinessObjectFormatEntity.java | 14 ++++ .../helper/BusinessObjectFormatHelper.java | 3 + .../impl/BusinessObjectFormatServiceImpl.java | 33 ++++++-- .../herd/service/AbstractServiceTest.java | 2 + .../BusinessObjectFormatServiceTest.java | 72 ++++++++++++++++++ .../BusinessObjectFormatServiceImplTest.java | 76 +++++++++++++++++++ 6 files changed, 194 insertions(+), 6 deletions(-) diff --git a/herd-code/herd-model/src/main/java/org/finra/herd/model/jpa/BusinessObjectFormatEntity.java b/herd-code/herd-model/src/main/java/org/finra/herd/model/jpa/BusinessObjectFormatEntity.java index 206bfa68da..05a0f1ffc2 100755 --- a/herd-code/herd-model/src/main/java/org/finra/herd/model/jpa/BusinessObjectFormatEntity.java +++ b/herd-code/herd-model/src/main/java/org/finra/herd/model/jpa/BusinessObjectFormatEntity.java @@ -130,6 +130,10 @@ public class BusinessObjectFormatEntity extends AuditableEntity @Type(type = "yes_no") private Boolean recordFlag; + @Column(name = "alw_non_bckwrds_cmptbl_chgs_fl", nullable = true) + @Type(type = "yes_no") + private Boolean allowNonBackwardsCompatibleChanges; + @Column(name = "rtntn_prd_days", nullable = true) private Integer retentionPeriodInDays; @@ -336,4 +340,14 @@ public void setRetentionType(RetentionTypeEntity retentionType) { this.retentionType = retentionType; } + + public Boolean isAllowNonBackwardsCompatibleChanges() + { + return allowNonBackwardsCompatibleChanges; + } + + public void setAllowNonBackwardsCompatibleChanges(Boolean allowNonBackwardsCompatibleChanges) + { + this.allowNonBackwardsCompatibleChanges = allowNonBackwardsCompatibleChanges; + } } diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/helper/BusinessObjectFormatHelper.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/helper/BusinessObjectFormatHelper.java index d7f9aaa635..9c9af06cb7 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/helper/BusinessObjectFormatHelper.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/helper/BusinessObjectFormatHelper.java @@ -239,6 +239,9 @@ public BusinessObjectFormat createBusinessObjectFormatFromEntity(BusinessObject businessObjectFormat.setRetentionType(latestVersionBusinessObjectFormatEntity.getRetentionType().getCode()); } + // Add business object format schema backwards compatibility changes flag. + businessObjectFormat.setAllowNonBackwardsCompatibleChanges(latestVersionBusinessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); + return businessObjectFormat; } diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java index 88e0631763..1b6dc84ee8 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java @@ -170,15 +170,17 @@ public BusinessObjectFormat createBusinessObjectFormat(BusinessObjectFormatCreat // Get the latest format version for this business format, if it exists. BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); - // If the latest version exists, perform the additive schema validation and update the latest entity. + // Check if the latest version exists. if (latestVersionBusinessObjectFormatEntity != null) { // Get the latest version business object format model object. BusinessObjectFormat latestVersionBusinessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(latestVersionBusinessObjectFormatEntity); - // If the latest version format has schema, check the new format version schema is "additive" to the previous format version. - if (latestVersionBusinessObjectFormat.getSchema() != null) + // If the latest version format schema exists and allowNonBackwardsCompatibleChanges is not true, + // then perform the additive schema validation and update the latest entity. + if (latestVersionBusinessObjectFormat.getSchema() != null && + BooleanUtils.isNotTrue(latestVersionBusinessObjectFormat.isAllowNonBackwardsCompatibleChanges())) { validateNewSchemaIsAdditiveToOldSchema(request.getSchema(), latestVersionBusinessObjectFormat.getSchema()); } @@ -229,12 +231,20 @@ public BusinessObjectFormat createBusinessObjectFormat(BusinessObjectFormatCreat newBusinessObjectFormatEntity.setRetentionPeriodInDays(latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays()); newBusinessObjectFormatEntity.setRecordFlag(latestVersionBusinessObjectFormatEntity.isRecordFlag()); newBusinessObjectFormatEntity.setRetentionType(latestVersionBusinessObjectFormatEntity.getRetentionType()); + + // Carry the schema backwards compatibility changes from the latest entity to the new entity. + newBusinessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(latestVersionBusinessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); + businessObjectFormatDao.saveAndRefresh(newBusinessObjectFormatEntity); - //reset the retention information of the latest version business object format + + //reset the retention information of the latest version business object format. latestVersionBusinessObjectFormatEntity.setRetentionType(null); latestVersionBusinessObjectFormatEntity.setRecordFlag(null); latestVersionBusinessObjectFormatEntity.setRetentionPeriodInDays(null); + // Reset the schema backwards compatibility changes of the latest version business object format. + latestVersionBusinessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(null); + businessObjectFormatDao.saveAndRefresh(latestVersionBusinessObjectFormatEntity); } @@ -729,15 +739,26 @@ public BusinessObjectFormat updateBusinessObjectFormatRetentionInformation(Busin public BusinessObjectFormat updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest) { - // Validate and trim the business object format schema backwards compatibility changes update request. + // Validate business object format schema backwards compatibility changes update request. Assert.notNull(businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest, "A business object format schema backwards compatibility changes update request must be specified."); Assert.notNull(businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest.isAllowNonBackwardsCompatibleChanges(), "allowNonBackwardsCompatibleChanges flag in business object format schema backwards compatibility changes update request must be specified."); + + // Validate and trim the business object format key parameters. businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey, false); Assert.isNull(businessObjectFormatKey.getBusinessObjectFormatVersion(), "Business object format version must not be specified."); - return null; + // Retrieve and ensure that a business object format exists. + BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey); + businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges( + BooleanUtils.isTrue(businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest.isAllowNonBackwardsCompatibleChanges())); + + // Persist and refresh the entity. + businessObjectFormatEntity = businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity); + + // Create and return the business object format object from the persisted entity. + return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity); } /** diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java index 771f3188ab..da9dad58f8 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/AbstractServiceTest.java @@ -614,6 +614,8 @@ public abstract class AbstractServiceTest extends AbstractDaoTest public static final Boolean RECORD_FLAG_SET = true; + public static final Boolean ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET = true; + public static final String RELATIONAL_SCHEMA_NAME = "UT_RelationalSchemaName_" + RANDOM_SUFFIX; public static final String RELATIONAL_TABLE_NAME = "UT_RelationalTableName_" + RANDOM_SUFFIX; diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java index 1b7c7ab9ae..72d3f6ebd2 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java @@ -61,6 +61,7 @@ import org.finra.herd.model.api.xml.BusinessObjectFormatKey; import org.finra.herd.model.api.xml.BusinessObjectFormatKeys; import org.finra.herd.model.api.xml.BusinessObjectFormatParentsUpdateRequest; +import org.finra.herd.model.api.xml.BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest; import org.finra.herd.model.api.xml.BusinessObjectFormatUpdateRequest; import org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat; import org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormatUpdateRequest; @@ -4651,7 +4652,78 @@ public void testUpdateBusinessObjectFormatAttributeDefinitionsBusinessObjectForm "Business object format with namespace \"%s\", business object definition name \"%s\", format usage \"%s\", format file type \"%s\", and format version \"%s\" doesn't exist.", NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION), ex.getMessage()); } + } + + @Test + public void testCreateBusinessObjectFormatWithAllowNonBackwardsCompatibleChangesSet() + { + // Create relative database entities. + businessObjectFormatServiceTestHelper.createTestDatabaseEntitiesForBusinessObjectFormatTesting(); + + // Create an initial version of a business object format with a schema. + BusinessObjectFormat businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatServiceTestHelper + .createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION, + businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), + businessObjectFormatServiceTestHelper.getTestSchema())); + + // Validate allowNonBackwardsCompatibleChanges is not set. + assertNull(businessObjectFormat.isAllowNonBackwardsCompatibleChanges()); + + // Create business object format key for the initial version of the format. + BusinessObjectFormatKey businessObjectFormatKey = + new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION); + + // Create a business object format create request with non-backwards compatible schema changes. + // Try to create a second version of the business object format with a schema that has a different null value. + Schema newSchema = businessObjectFormatServiceTestHelper.getTestSchema(); + newSchema.setNullValue(SCHEMA_NULL_VALUE_NULL_WORD); + BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest = businessObjectFormatServiceTestHelper + .createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION, + businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), newSchema); + + // We expected to fail as allowNonBackwardsCompatibleChanges is not set. + try + { + businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest); + fail(); + } + catch (IllegalArgumentException e) + { + assertEquals("New format version schema is not \"additive\" to the previous format version schema. " + + "New format version null value does not match to the previous format version null value.", e.getMessage()); + } + + // Get the business object format entity by alternate key. + BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); + assertNotNull(businessObjectFormatEntity); + + // Update allowNonBackwardsCompatibleChanges to true. + businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(true); + assertTrue(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); + + // Call create business object format when allowNonBackwardsCompatibleChanges is set to true + businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest); + + // Validate results. + assertNotNull(businessObjectFormat); + assertEquals(true, businessObjectFormat.isAllowNonBackwardsCompatibleChanges()); + assertEquals(SECOND_FORMAT_VERSION, Integer.valueOf(businessObjectFormat.getBusinessObjectFormatVersion())); + + // Get the business object format entity by alternate key. + businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); + assertNotNull(businessObjectFormatEntity); + + // Update allowNonBackwardsCompatibleChanges to false. + businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(false); + assertFalse(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); + + // Call create business object format when allowNonBackwardsCompatibleChanges is set to false + businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest); + // Validate results. + assertNotNull(businessObjectFormat); + assertEquals(false, businessObjectFormat.isAllowNonBackwardsCompatibleChanges()); + assertEquals(THIRD_FORMAT_VERSION, Integer.valueOf(businessObjectFormat.getBusinessObjectFormatVersion())); } private GlobalAttributeDefinitionEntity createGlobalAttributeDefinitionEntityWithAllowedAttributeValues() diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImplTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImplTest.java index 0aa410d5b7..8d7c3452bb 100644 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImplTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImplTest.java @@ -34,6 +34,7 @@ import org.finra.herd.model.api.xml.BusinessObjectFormat; import org.finra.herd.model.api.xml.BusinessObjectFormatKey; import org.finra.herd.model.api.xml.BusinessObjectFormatRetentionInformationUpdateRequest; +import org.finra.herd.model.api.xml.BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest; import org.finra.herd.model.jpa.BusinessObjectFormatEntity; import org.finra.herd.model.jpa.RetentionTypeEntity; import org.finra.herd.service.AbstractServiceTest; @@ -398,6 +399,81 @@ public void testUpdateBusinessObjectFormatRetentionInformationRetentionDateReten verifyNoMoreInteractionsHelper(); } + @Test + public void testUpdateBusinessObjectFormatSchemaBackwardsCompatibilityChanges() + { + // Create a business object format key without version. + BusinessObjectFormatKey businessObjectFormatKey = + new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION); + + // Create a business object format schema backwards compatibility changes update request. + BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest = + new BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest(ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET); + + // Create a business object format entity. + BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity(); + + // Create a business object format. + BusinessObjectFormat businessObjectFormat = new BusinessObjectFormat(); + businessObjectFormat.setId(ID); + + // Mock the external calls. + when(businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey)).thenReturn(businessObjectFormatEntity); + when(businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity)).thenReturn(businessObjectFormatEntity); + when(businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity)).thenReturn(businessObjectFormat); + + // Call the method under test. + BusinessObjectFormat result = businessObjectFormatServiceImpl.updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(businessObjectFormatKey, + businessObjectFormatSchemaBackwardsCompatibilityUpdateRequest); + + // Verify the external calls. + verify(businessObjectFormatHelper).validateBusinessObjectFormatKey(businessObjectFormatKey, false); + verify(businessObjectFormatDaoHelper).getBusinessObjectFormatEntity(businessObjectFormatKey); + verify(businessObjectFormatDao).saveAndRefresh(businessObjectFormatEntity); + verify(businessObjectFormatHelper).createBusinessObjectFormatFromEntity(businessObjectFormatEntity); + verifyNoMoreInteractionsHelper(); + + // Validate the results. + assertEquals(businessObjectFormat, result); + assertEquals(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges(), ALLOW_NON_BACKWARDS_COMPATIBLE_CHANGES_SET); + } + + @Test + public void testUpdateBusinessObjectFormatSchemaBackwardsCompatibilityChangesMissingRequiredParameters() + { + // Create a business object format key without version. + BusinessObjectFormatKey businessObjectFormatKey = + new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION); + + // Try to call the method under test without specifying a business object format schema backwards compatibility changes update request. + try + { + businessObjectFormatServiceImpl.updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(businessObjectFormatKey, null); + fail(); + } + catch (IllegalArgumentException e) + { + assertEquals("A business object format schema backwards compatibility changes update request must be specified.", e.getMessage()); + } + + // Try to call the method under test without specifying a record flag. + try + { + businessObjectFormatServiceImpl.updateBusinessObjectFormatSchemaBackwardsCompatibilityChanges(businessObjectFormatKey, + new BusinessObjectFormatSchemaBackwardsCompatibilityUpdateRequest(null)); + fail(); + } + catch (IllegalArgumentException e) + { + assertEquals( + "allowNonBackwardsCompatibleChanges flag in business object format schema backwards compatibility changes update request must be specified.", + e.getMessage()); + } + + // Verify the external calls. + verifyNoMoreInteractionsHelper(); + } + /** * Checks if any of the mocks has any interaction. */ From 91a7d0fcb9d74d941722d6238bc655caa0bbd8f0 Mon Sep 17 00:00:00 2001 From: K26992 Date: Fri, 25 May 2018 11:37:31 -0400 Subject: [PATCH 09/11] DM-10653 ( Allow non-backwards compatible Schema changes based on Format indicator) - updated Unit test --- .../BusinessObjectFormatServiceTest.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java index 72d3f6ebd2..91067ce373 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java @@ -4671,7 +4671,7 @@ public void testCreateBusinessObjectFormatWithAllowNonBackwardsCompatibleChanges // Create business object format key for the initial version of the format. BusinessObjectFormatKey businessObjectFormatKey = - new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION); + new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION); // Create a business object format create request with non-backwards compatible schema changes. // Try to create a second version of the business object format with a schema that has a different null value. @@ -4697,33 +4697,37 @@ public void testCreateBusinessObjectFormatWithAllowNonBackwardsCompatibleChanges BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); assertNotNull(businessObjectFormatEntity); - // Update allowNonBackwardsCompatibleChanges to true. - businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(true); - assertTrue(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); - - // Call create business object format when allowNonBackwardsCompatibleChanges is set to true - businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest); + // Update allowNonBackwardsCompatibleChanges to false. + businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(false); + assertFalse(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); - // Validate results. - assertNotNull(businessObjectFormat); - assertEquals(true, businessObjectFormat.isAllowNonBackwardsCompatibleChanges()); - assertEquals(SECOND_FORMAT_VERSION, Integer.valueOf(businessObjectFormat.getBusinessObjectFormatVersion())); + // We expected to fail as allowNonBackwardsCompatibleChanges is set to false. + try + { + businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest); + fail(); + } + catch (IllegalArgumentException e) + { + assertEquals("New format version schema is not \"additive\" to the previous format version schema. " + + "New format version null value does not match to the previous format version null value.", e.getMessage()); + } // Get the business object format entity by alternate key. businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); assertNotNull(businessObjectFormatEntity); - // Update allowNonBackwardsCompatibleChanges to false. - businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(false); - assertFalse(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); + // Update allowNonBackwardsCompatibleChanges to true. + businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(true); + assertTrue(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); - // Call create business object format when allowNonBackwardsCompatibleChanges is set to false + // Call create business object format when allowNonBackwardsCompatibleChanges is set to true. businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest); // Validate results. assertNotNull(businessObjectFormat); - assertEquals(false, businessObjectFormat.isAllowNonBackwardsCompatibleChanges()); - assertEquals(THIRD_FORMAT_VERSION, Integer.valueOf(businessObjectFormat.getBusinessObjectFormatVersion())); + assertEquals(true, businessObjectFormat.isAllowNonBackwardsCompatibleChanges()); + assertEquals(SECOND_FORMAT_VERSION, Integer.valueOf(businessObjectFormat.getBusinessObjectFormatVersion())); } private GlobalAttributeDefinitionEntity createGlobalAttributeDefinitionEntityWithAllowedAttributeValues() From e469d2d5bd3d0d9a3a6890b6c54d3c0f2febac45 Mon Sep 17 00:00:00 2001 From: Mona Annaparthi Date: Tue, 29 May 2018 13:10:19 -0400 Subject: [PATCH 10/11] DM-10653 ( Allow non-backwards compatible Schema changes based on Format indicator) - Address regression test results --- .../impl/BusinessObjectFormatServiceImpl.java | 6 ++ ...nalTableRegistrationHelperServiceImpl.java | 4 + .../BusinessObjectFormatServiceTest.java | 78 ++++++++++++------- ...elationalTableRegistrationServiceTest.java | 2 + 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java index 1b6dc84ee8..127ca2602d 100755 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java @@ -427,6 +427,12 @@ public BusinessObjectFormat deleteBusinessObjectFormat(BusinessObjectFormatKey b previousVersionBusinessObjectFormatEntity.setRecordFlag(businessObjectFormatEntity.isRecordFlag()); previousVersionBusinessObjectFormatEntity.setRetentionPeriodInDays(businessObjectFormatEntity.getRetentionPeriodInDays()); previousVersionBusinessObjectFormatEntity.setRetentionType(businessObjectFormatEntity.getRetentionType()); + + // Update the previous version schema compatibility changes information. + previousVersionBusinessObjectFormatEntity + .setAllowNonBackwardsCompatibleChanges(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); + + // Save the updated entity. businessObjectFormatDao.saveAndRefresh(previousVersionBusinessObjectFormatEntity); } } diff --git a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/RelationalTableRegistrationHelperServiceImpl.java b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/RelationalTableRegistrationHelperServiceImpl.java index 816e385c2a..0e49807062 100644 --- a/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/RelationalTableRegistrationHelperServiceImpl.java +++ b/herd-code/herd-service/src/main/java/org/finra/herd/service/impl/RelationalTableRegistrationHelperServiceImpl.java @@ -396,6 +396,10 @@ BusinessObjectData registerRelationalTableImpl(RelationalTableRegistrationCreate BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatHelper.getBusinessObjectFormatKey(businessObjectFormat)); + // Allow non-backwards-compatible schema changes. + businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(true); + businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity); + // Get a business object data status entity for the VALID status. BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(BusinessObjectDataStatusEntity.VALID); diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java index 91067ce373..0a8a208af4 100755 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java @@ -4661,26 +4661,27 @@ public void testCreateBusinessObjectFormatWithAllowNonBackwardsCompatibleChanges businessObjectFormatServiceTestHelper.createTestDatabaseEntitiesForBusinessObjectFormatTesting(); // Create an initial version of a business object format with a schema. - BusinessObjectFormat businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatServiceTestHelper + BusinessObjectFormat businessObjectFormatV0 = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatServiceTestHelper .createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), businessObjectFormatServiceTestHelper.getTestSchema())); - // Validate allowNonBackwardsCompatibleChanges is not set. - assertNull(businessObjectFormat.isAllowNonBackwardsCompatibleChanges()); + // Validate allowNonBackwardsCompatibleChanges is not set on businessObjectFormatV0 + assertNull(businessObjectFormatV0.isAllowNonBackwardsCompatibleChanges()); - // Create business object format key for the initial version of the format. - BusinessObjectFormatKey businessObjectFormatKey = + // Create business object format key for format V0. + BusinessObjectFormatKey businessObjectFormatKeyV0 = new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION); - // Create a business object format create request with non-backwards compatible schema changes. - // Try to create a second version of the business object format with a schema that has a different null value. - Schema newSchema = businessObjectFormatServiceTestHelper.getTestSchema(); - newSchema.setNullValue(SCHEMA_NULL_VALUE_NULL_WORD); + // Create a business object format create request with non-backwards compatible schema changes, schema that has a different null value. + Schema nonBackwardsCompatibleSchema = businessObjectFormatServiceTestHelper.getTestSchema(); + nonBackwardsCompatibleSchema.setNullValue(SCHEMA_NULL_VALUE_NULL_WORD); BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest = businessObjectFormatServiceTestHelper .createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION, - businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), newSchema); + businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), + nonBackwardsCompatibleSchema); + // Try to create a second version of the business object format with non-backwards compatible schema changes. // We expected to fail as allowNonBackwardsCompatibleChanges is not set. try { @@ -4693,14 +4694,15 @@ public void testCreateBusinessObjectFormatWithAllowNonBackwardsCompatibleChanges "New format version null value does not match to the previous format version null value.", e.getMessage()); } - // Get the business object format entity by alternate key. - BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); - assertNotNull(businessObjectFormatEntity); + // Get the initial format version of the business object format entity. + BusinessObjectFormatEntity businessObjectFormatEntityV0 = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKeyV0); + assertNotNull(businessObjectFormatEntityV0); - // Update allowNonBackwardsCompatibleChanges to false. - businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(false); - assertFalse(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); + // Update businessObjectFormatEntityV0 to allowNonBackwardsCompatibleChanges to false. + businessObjectFormatEntityV0.setAllowNonBackwardsCompatibleChanges(false); + assertFalse(businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges()); + // Try to create a second version of the business object format with non-backwards compatible schema changes.. // We expected to fail as allowNonBackwardsCompatibleChanges is set to false. try { @@ -4713,21 +4715,43 @@ public void testCreateBusinessObjectFormatWithAllowNonBackwardsCompatibleChanges "New format version null value does not match to the previous format version null value.", e.getMessage()); } - // Get the business object format entity by alternate key. - businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey); - assertNotNull(businessObjectFormatEntity); + // Get the initial format version and validate that the allowNonBackwardsCompatibleChanges is set to false. + businessObjectFormatV0 = businessObjectFormatService.getBusinessObjectFormat(businessObjectFormatKeyV0); + assertFalse(businessObjectFormatV0.isAllowNonBackwardsCompatibleChanges()); - // Update allowNonBackwardsCompatibleChanges to true. - businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(true); - assertTrue(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges()); + // Update businessObjectFormatEntityV0 to allowNonBackwardsCompatibleChanges to true. + businessObjectFormatEntityV0.setAllowNonBackwardsCompatibleChanges(true); + assertTrue(businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges()); // Call create business object format when allowNonBackwardsCompatibleChanges is set to true. - businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest); + BusinessObjectFormat businessObjectFormatV1 = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest); + + // Validate businessObjectFormatV1 and businessObjectFormatEntityV0. + assertNotNull(businessObjectFormatV1); + assertEquals(true, businessObjectFormatV1.isAllowNonBackwardsCompatibleChanges()); + assertEquals(SECOND_FORMAT_VERSION, Integer.valueOf(businessObjectFormatV1.getBusinessObjectFormatVersion())); + assertNull(businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges()); + + // Get the initial format version and validate that the allowNonBackwardsCompatibleChanges is set to true. + businessObjectFormatV0 = businessObjectFormatService.getBusinessObjectFormat(businessObjectFormatKeyV0); + assertTrue(businessObjectFormatV0.isAllowNonBackwardsCompatibleChanges()); + + // Delete the second version of business object format. + BusinessObjectFormat deletedBusinessObjectFormat = businessObjectFormatService + .deleteBusinessObjectFormat(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, SECOND_FORMAT_VERSION)); + assertNotNull(deletedBusinessObjectFormat); + assertTrue(deletedBusinessObjectFormat.isAllowNonBackwardsCompatibleChanges()); + + // Get the initial format version of the business object format entity. + businessObjectFormatEntityV0 = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKeyV0); + + // Validate the schema compatibility changes got propagated to the latest format version. + assertNotNull(businessObjectFormatEntityV0); + assertEquals(true, businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges()); + assertEquals(INITIAL_FORMAT_VERSION, Integer.valueOf(businessObjectFormatEntityV0.getBusinessObjectFormatVersion())); - // Validate results. - assertNotNull(businessObjectFormat); - assertEquals(true, businessObjectFormat.isAllowNonBackwardsCompatibleChanges()); - assertEquals(SECOND_FORMAT_VERSION, Integer.valueOf(businessObjectFormat.getBusinessObjectFormatVersion())); + // Validate initial version business object format entity. + assertTrue(businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges()); } private GlobalAttributeDefinitionEntity createGlobalAttributeDefinitionEntityWithAllowedAttributeValues() diff --git a/herd-code/herd-service/src/test/java/org/finra/herd/service/RelationalTableRegistrationServiceTest.java b/herd-code/herd-service/src/test/java/org/finra/herd/service/RelationalTableRegistrationServiceTest.java index a04b1731a4..8a15eae358 100644 --- a/herd-code/herd-service/src/test/java/org/finra/herd/service/RelationalTableRegistrationServiceTest.java +++ b/herd-code/herd-service/src/test/java/org/finra/herd/service/RelationalTableRegistrationServiceTest.java @@ -137,6 +137,7 @@ public void testCreateRelationalTableRegistration() new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME), relationalTableName))); expectedBusinessObjectFormat.setSchema(expectedSchema); + expectedBusinessObjectFormat.setAllowNonBackwardsCompatibleChanges(true); // Validate the newly created business object format. assertEquals(expectedBusinessObjectFormat, resultBusinessObjectFormat); @@ -248,6 +249,7 @@ public void testCreateRelationalTableRegistrationWithAppendToExistingBusinessObj new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME), relationalTableName))); expectedBusinessObjectFormat.setSchema(expectedSchema); + expectedBusinessObjectFormat.setAllowNonBackwardsCompatibleChanges(true); // Validate the newly created business object format. assertEquals(expectedBusinessObjectFormat, businessObjectFormat); From bbeb9ceed72593c0a5fc0e2838e09f0305890c6b Mon Sep 17 00:00:00 2001 From: Val Sorokine Date: Thu, 31 May 2018 13:39:22 -0400 Subject: [PATCH 11/11] Added initial version of the herd.postgres.0.70.0-to-0.71.0.upgrade.sql script --- ...herd.postgres.0.70.0-to-0.71.0.upgrade.sql | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 herd-build/herd-scripts/herd-scripts-sql/src/main/resources/herd.postgres.0.70.0-to-0.71.0.upgrade.sql diff --git a/herd-build/herd-scripts/herd-scripts-sql/src/main/resources/herd.postgres.0.70.0-to-0.71.0.upgrade.sql b/herd-build/herd-scripts/herd-scripts-sql/src/main/resources/herd.postgres.0.70.0-to-0.71.0.upgrade.sql new file mode 100644 index 0000000000..65510fb668 --- /dev/null +++ b/herd-build/herd-scripts/herd-scripts-sql/src/main/resources/herd.postgres.0.70.0-to-0.71.0.upgrade.sql @@ -0,0 +1,26 @@ +/* +* Copyright 2015 herd contributors +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +--bus_objct_frmt + +alter table bus_objct_frmt add column alw_non_bckwrds_cmptbl_chgs_fl char(1); + +alter table bus_objct_frmt add constraint bus_objct_frmt_ck3 check (alw_non_bckwrds_cmptbl_chgs_fl in ('Y', 'N')); + +--scrty_fn_lk + +insert into scrty_fn_lk (scrty_fn_cd, creat_ts, creat_user_id, updt_ts, updt_user_id) +values ('FN_BUSINESS_OBJECT_FORMAT_SCHEMA_BACKWARDS_COMPATIBILITY_PUT', current_timestamp, 'SYSTEM', current_timestamp, 'SYSTEM');