Search in sources :

Example 1 with AssetCodeRelationshipKind

use of com.khartec.waltz.model.application.AssetCodeRelationshipKind in project waltz by khartec.

the class ApplicationService method findRelated.

public Map<AssetCodeRelationshipKind, List<Application>> findRelated(long appId) {
    List<Application> related = applicationDao.findRelatedByApplicationId(appId);
    Optional<Application> foundApp = related.stream().filter(app -> app.id().equals(Optional.of(appId))).findFirst();
    if (foundApp.isPresent()) {
        Application app = foundApp.get();
        Function<Application, AssetCodeRelationshipKind> classifier = relatedApp -> {
            boolean sameParent = relatedApp.parentAssetCode().equals(app.parentAssetCode());
            boolean sameCode = relatedApp.assetCode().equals(app.assetCode());
            boolean isParent = relatedApp.assetCode().equals(app.parentAssetCode());
            boolean isChild = relatedApp.parentAssetCode().equals(app.assetCode());
            if (sameCode) {
                return AssetCodeRelationshipKind.SHARING;
            } else if (isParent) {
                return AssetCodeRelationshipKind.PARENT;
            } else if (isChild) {
                return AssetCodeRelationshipKind.CHILD;
            } else if (sameParent && app.parentAssetCode().isPresent()) {
                return AssetCodeRelationshipKind.SIBLING;
            } else {
                return AssetCodeRelationshipKind.NONE;
            }
        };
        Map<AssetCodeRelationshipKind, List<Application>> grouped = related.stream().filter(// can do simple ref check here
        relatedApp -> relatedApp != app).collect(Collectors.groupingBy(classifier));
        return grouped;
    } else {
        return emptyMap();
    }
}
Also used : ApplicationIdSelectorFactory(com.khartec.waltz.data.application.ApplicationIdSelectorFactory) AppRegistrationResponse(com.khartec.waltz.model.application.AppRegistrationResponse) ImmutableEntityReference(com.khartec.waltz.model.ImmutableEntityReference) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityReference(com.khartec.waltz.model.EntityReference) AppRegistrationRequest(com.khartec.waltz.model.application.AppRegistrationRequest) AssetCodeRelationshipKind(com.khartec.waltz.model.application.AssetCodeRelationshipKind) Function(java.util.function.Function) EntityKind(com.khartec.waltz.model.EntityKind) EntityAliasDao(com.khartec.waltz.data.entity_alias.EntityAliasDao) IdSelectionOptions(com.khartec.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1) Checks.checkNotEmpty(com.khartec.waltz.common.Checks.checkNotEmpty) Service(org.springframework.stereotype.Service) Map(java.util.Map) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) Select(org.jooq.Select) Application(com.khartec.waltz.model.application.Application) Collections.emptyMap(java.util.Collections.emptyMap) ApplicationDao(com.khartec.waltz.data.application.ApplicationDao) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) Collection(java.util.Collection) ApplicationSearchDao(com.khartec.waltz.data.application.search.ApplicationSearchDao) Tally(com.khartec.waltz.model.tally.Tally) Collectors(java.util.stream.Collectors) List(java.util.List) Optional(java.util.Optional) EntityTagDao(com.khartec.waltz.data.entity_tag.EntityTagDao) AssetCodeRelationshipKind(com.khartec.waltz.model.application.AssetCodeRelationshipKind) List(java.util.List) Application(com.khartec.waltz.model.application.Application)

Aggregations

Checks.checkNotEmpty (com.khartec.waltz.common.Checks.checkNotEmpty)1 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)1 ApplicationDao (com.khartec.waltz.data.application.ApplicationDao)1 ApplicationIdSelectorFactory (com.khartec.waltz.data.application.ApplicationIdSelectorFactory)1 ApplicationSearchDao (com.khartec.waltz.data.application.search.ApplicationSearchDao)1 EntityAliasDao (com.khartec.waltz.data.entity_alias.EntityAliasDao)1 EntityTagDao (com.khartec.waltz.data.entity_tag.EntityTagDao)1 EntityKind (com.khartec.waltz.model.EntityKind)1 EntityReference (com.khartec.waltz.model.EntityReference)1 IdSelectionOptions (com.khartec.waltz.model.IdSelectionOptions)1 ImmutableEntityReference (com.khartec.waltz.model.ImmutableEntityReference)1 AppRegistrationRequest (com.khartec.waltz.model.application.AppRegistrationRequest)1 AppRegistrationResponse (com.khartec.waltz.model.application.AppRegistrationResponse)1 Application (com.khartec.waltz.model.application.Application)1 AssetCodeRelationshipKind (com.khartec.waltz.model.application.AssetCodeRelationshipKind)1 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)1 Tally (com.khartec.waltz.model.tally.Tally)1 Collection (java.util.Collection)1 Collections.emptyMap (java.util.Collections.emptyMap)1 List (java.util.List)1