/** * Gets a tag entity and ensure it exists. * * @param tagKey the tag key (case insensitive) * * @return the tag entity * @throws org.finra.herd.model.ObjectNotFoundException if the tag entity doesn't exist */ public TagEntity getTagEntity(TagKey tagKey) throws ObjectNotFoundException { TagEntity tagEntity = tagDao.getTagByKey(tagKey); if (tagEntity == null) { throw new ObjectNotFoundException( String.format("Tag with code \"%s\" doesn't exist for tag type \"%s\".", tagKey.getTagCode(), tagKey.getTagTypeCode())); } return tagEntity; }
@Override public boolean indexSizeCheckValidationTags(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Simple count validation, index size should equal entity list size final long indexSize = indexFunctionsDao.getNumberOfTypesInIndex(indexName, documentType); final long tagDatabaseTableSize = tagDao.getCountOfAllTags(); if (tagDatabaseTableSize != indexSize) { LOGGER.error("Index validation failed, tag database table size {}, does not equal index size {}.", tagDatabaseTableSize, indexSize); } return tagDatabaseTableSize == indexSize; }
@Override public boolean indexSpotCheckMostRecentValidationTags(String indexName) { final Integer spotCheckMostRecentNumber = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class); // Get a list of all tags final List<TagEntity> tagEntityList = Collections.unmodifiableList(tagDao.getMostRecentTags(spotCheckMostRecentNumber)); return indexValidateTagsList(tagEntityList); }
tagEntities.addAll(tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, tagSearchKey.getParentTagCode(), tagSearchKey.isIsParentTagNull())); tagEntities.addAll(tagDao.getTags());
@Override public boolean indexSpotCheckPercentageValidationTags(String indexName) { final Double spotCheckPercentage = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_PERCENTAGE, Double.class); // Get a list of all tags final List<TagEntity> tagEntityList = Collections.unmodifiableList(tagDao.getPercentageOfAllTags(spotCheckPercentage)); return indexValidateTagsList(tagEntityList); }
@Override @Async public Future<Void> indexValidateAllTags(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Get a list of all tags final List<TagEntity> tagEntityList = Collections.unmodifiableList(tagDao.getTags()); // Remove any index documents that are not in the database removeAnyIndexDocumentsThatAreNotInTagsList(indexName, documentType, tagEntityList); // Validate all Tags tagHelper.executeFunctionForTagEntities(indexName, documentType, tagEntityList, indexFunctionsDao::validateDocumentIndex); // Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they // can call "get" to see if any exceptions were thrown. return new AsyncResult<>(null); }
@Override public void updateSearchIndexDocumentTag(SearchIndexUpdateDto searchIndexUpdateDto) { final String indexName = SearchIndexTypeEntity.SearchIndexTypes.TAG.name().toLowerCase(); final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); String modificationType = searchIndexUpdateDto.getModificationType(); List<Integer> ids = searchIndexUpdateDto.getTagIds(); LOGGER.info("Updating the search index document representation(s) of the tag(s)." + " tagIds=[{}], searchIndexUpdateType=\"{}\"", ids.stream().map(String::valueOf).collect(Collectors.joining(", ")), modificationType); // Switch on the type of CRUD modification to be done switch (modificationType) { case SEARCH_INDEX_UPDATE_TYPE_CREATE: // Create a search index document indexFunctionsDao.createIndexDocuments(indexName, documentType, convertTagEntityListToJSONStringMap(tagDao.getTagsByIds(ids))); break; case SEARCH_INDEX_UPDATE_TYPE_UPDATE: // Update a search index document indexFunctionsDao.updateIndexDocuments(indexName, documentType, convertTagEntityListToJSONStringMap(tagDao.getTagsByIds(ids))); break; case SEARCH_INDEX_UPDATE_TYPE_DELETE: // Delete a search index document indexFunctionsDao.deleteIndexDocuments(indexName, documentType, ids); break; default: LOGGER.warn("Unknown modification type received."); break; } }
/** * Ensures that a tag entity does not exist for a specified tag type code and display name. * * @param tagCode the specified tag type code. * @param displayName the specified display name. */ public void assertDisplayNameDoesNotExistForTag(String tagCode, String displayName) { TagEntity tagEntity = tagDao.getTagByTagTypeAndDisplayName(tagCode, displayName); if (tagEntity != null) { throw new AlreadyExistsException(String .format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", displayName, tagEntity.getTagType().getCode(), tagEntity.getTagCode())); } }
/** * Create a list of tag entities along with all its children tags down the hierarchy up to maximum allowed tag nesting level. * * @param parentTagEntity the parent tag entity * * @return the list of tag children entities */ public List<TagEntity> getTagChildrenEntities(TagEntity parentTagEntity) { // Get the maximum allowed tag nesting level. Integer maxAllowedTagNesting = configurationHelper.getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class); // Build a list of the specified tag along with all its children tags down the hierarchy up to maximum allowed tag nesting level. List<TagEntity> parentTagEntities = new ArrayList<>(); parentTagEntities.add(parentTagEntity); List<TagEntity> tagEntities = new ArrayList<>(); for (int level = 0; !parentTagEntities.isEmpty() && level < maxAllowedTagNesting; level++) { parentTagEntities = tagDao.getChildrenTags(parentTagEntities); tagEntities.addAll(parentTagEntities); } return tagEntities; }
tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE, null)); tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toUpperCase(), null)); tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toLowerCase(), null)); assertTrue(tagDao.getTagsByTagTypeAndParentTagCode(I_DO_NOT_EXIST, null).isEmpty()); tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE, TAG_CODE)); tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toUpperCase(), TAG_CODE.toUpperCase())); tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toLowerCase(), TAG_CODE.toLowerCase())); assertTrue(tagDao.getTagsByTagTypeAndParentTagCode(I_DO_NOT_EXIST, TAG_CODE).isEmpty()); assertTrue(tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE, I_DO_NOT_EXIST).isEmpty());
List<TagEntity> tagEntities = tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, null, null); List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = businessObjectDefinitionDao.getBusinessObjectDefinitions(tagEntities); LOGGER.info("Modify the business object definitions in the search index associated with the tag type being updated." +
@Override public boolean indexSpotCheckPercentageValidationTags(String indexName) { final Double spotCheckPercentage = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_PERCENTAGE, Double.class); // Get a list of all tags final List<TagEntity> tagEntityList = Collections.unmodifiableList(tagDao.getPercentageOfAllTags(spotCheckPercentage)); return indexValidateTagsList(tagEntityList); }
@Override @Async public Future<Void> indexValidateAllTags(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Get a list of all tags final List<TagEntity> tagEntityList = Collections.unmodifiableList(tagDao.getTags()); // Remove any index documents that are not in the database removeAnyIndexDocumentsThatAreNotInTagsList(indexName, documentType, tagEntityList); // Validate all Tags tagHelper.executeFunctionForTagEntities(indexName, documentType, tagEntityList, indexFunctionsDao::validateDocumentIndex); // Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they // can call "get" to see if any exceptions were thrown. return new AsyncResult<>(null); }
@Override public void updateSearchIndexDocumentTag(SearchIndexUpdateDto searchIndexUpdateDto) { final String indexName = SearchIndexTypeEntity.SearchIndexTypes.TAG.name().toLowerCase(); final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); String modificationType = searchIndexUpdateDto.getModificationType(); List<Integer> ids = searchIndexUpdateDto.getTagIds(); LOGGER.info("Updating the search index document representation(s) of the tag(s)." + " tagIds=[{}], searchIndexUpdateType=\"{}\"", ids.stream().map(String::valueOf).collect(Collectors.joining(", ")), modificationType); // Switch on the type of CRUD modification to be done switch (modificationType) { case SEARCH_INDEX_UPDATE_TYPE_CREATE: // Create a search index document indexFunctionsDao.createIndexDocuments(indexName, documentType, convertTagEntityListToJSONStringMap(tagDao.getTagsByIds(ids))); break; case SEARCH_INDEX_UPDATE_TYPE_UPDATE: // Update a search index document indexFunctionsDao.updateIndexDocuments(indexName, documentType, convertTagEntityListToJSONStringMap(tagDao.getTagsByIds(ids))); break; case SEARCH_INDEX_UPDATE_TYPE_DELETE: // Delete a search index document indexFunctionsDao.deleteIndexDocuments(indexName, documentType, ids); break; default: LOGGER.warn("Unknown modification type received."); break; } }
tagEntities.addAll(tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, tagSearchKey.getParentTagCode(), tagSearchKey.isIsParentTagNull())); tagEntities.addAll(tagDao.getTags());
/** * Ensures that a tag entity does not exist for a specified tag type code and display name. * * @param tagCode the specified tag type code. * @param displayName the specified display name. */ public void assertDisplayNameDoesNotExistForTag(String tagCode, String displayName) { TagEntity tagEntity = tagDao.getTagByTagTypeAndDisplayName(tagCode, displayName); if (tagEntity != null) { throw new AlreadyExistsException(String .format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", displayName, tagEntity.getTagType().getCode(), tagEntity.getTagCode())); } }
/** * Create a list of tag entities along with all its children tags down the hierarchy up to maximum allowed tag nesting level. * * @param parentTagEntity the parent tag entity * * @return the list of tag children entities */ public List<TagEntity> getTagChildrenEntities(TagEntity parentTagEntity) { // Get the maximum allowed tag nesting level. Integer maxAllowedTagNesting = configurationHelper.getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class); // Build a list of the specified tag along with all its children tags down the hierarchy up to maximum allowed tag nesting level. List<TagEntity> parentTagEntities = new ArrayList<>(); parentTagEntities.add(parentTagEntity); List<TagEntity> tagEntities = new ArrayList<>(); for (int level = 0; !parentTagEntities.isEmpty() && level < maxAllowedTagNesting; level++) { parentTagEntities = tagDao.getChildrenTags(parentTagEntities); tagEntities.addAll(parentTagEntities); } return tagEntities; }
@Override public TagListResponse getTags(String tagTypeCode, String tagCode) { // Validate and trim the tag type code. String tagTypeCodeLocal = alternateKeyHelper.validateStringParameter("tag type code", tagTypeCode); String cleanTagCode = tagCode; // Retrieve and ensure that a tag type exists for the specified tag type code. tagTypeDaoHelper.getTagTypeEntity(new TagTypeKey(tagTypeCodeLocal)); // Get the list of tag keys. TagListResponse response = new TagListResponse(); //not root, need to set the tag key and parent tag key //getTag method will validate the requested tag exists if (tagCode != null) { cleanTagCode = alternateKeyHelper.validateStringParameter("tag code", tagCode); TagKey tagKey = new TagKey(tagTypeCodeLocal, cleanTagCode); Tag tag = getTag(tagKey); response.setTagKey(tag.getTagKey()); response.setParentTagKey(tag.getParentTagKey()); } List<TagChild> tagChildren = tagDao.getTagsByTagTypeAndParentTagCode(tagTypeCodeLocal, cleanTagCode); response.setTagChildren(tagChildren); return response; }
List<TagEntity> tagEntities = tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, null, null); List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = businessObjectDefinitionDao.getBusinessObjectDefinitions(tagEntities); LOGGER.info("Modify the business object definitions in the search index associated with the tag type being updated." +
/** * Gets a tag entity and ensure it exists. * * @param tagKey the tag key (case insensitive) * * @return the tag entity * @throws org.finra.herd.model.ObjectNotFoundException if the tag entity doesn't exist */ public TagEntity getTagEntity(TagKey tagKey) throws ObjectNotFoundException { TagEntity tagEntity = tagDao.getTagByKey(tagKey); if (tagEntity == null) { throw new ObjectNotFoundException( String.format("Tag with code \"%s\" doesn't exist for tag type \"%s\".", tagKey.getTagCode(), tagKey.getTagTypeCode())); } return tagEntity; }