use of com.khartec.waltz.model.application.Application 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();
}
}
use of com.khartec.waltz.model.application.Application in project waltz by khartec.
the class AuthoritativeSourceService method logInsert.
private void logInsert(AuthoritativeSourceCreateCommand command, String username) {
OrganisationalUnit orgUnit = organisationalUnitDao.getById(command.orgUnitId());
DataType dataType = dataTypeDao.getById(command.dataTypeId());
Application app = applicationDao.getById(command.applicationId());
if (app != null && dataType != null && orgUnit != null) {
String msg = String.format("Registered %s as an authoritative source for type: %s for org: %s", app.name(), dataType.name(), orgUnit.name());
tripleLog(username, orgUnit, dataType, app, msg, Operation.ADD);
}
}
use of com.khartec.waltz.model.application.Application in project waltz by khartec.
the class AuthoritativeSourceService method logUpdate.
private void logUpdate(AuthoritativeSourceUpdateCommand command, String username) {
AuthoritativeSource authSource = getById(command.id().get());
if (authSource == null) {
return;
}
OrganisationalUnit orgUnit = organisationalUnitDao.getById(authSource.parentReference().id());
DataType dataType = dataTypeDao.getByCode(authSource.dataType());
Application app = applicationDao.getById(authSource.applicationReference().id());
if (app != null && dataType != null && orgUnit != null) {
String msg = String.format("Updated %s as an authoritative source for type: %s for org: %s", app.name(), dataType.name(), orgUnit.name());
tripleLog(username, orgUnit, dataType, app, msg, Operation.UPDATE);
}
}
use of com.khartec.waltz.model.application.Application in project waltz by khartec.
the class LogicalFlowDecoratorRatingsCalculator method lookupVantagePoint.
private EntityReference lookupVantagePoint(Map<Long, Application> targetAppsById, LogicalFlow flow) {
Application targetApp = targetAppsById.get(flow.target().id());
long targetOrgUnitId = targetApp.organisationalUnitId();
return EntityReference.mkRef(EntityKind.ORG_UNIT, targetOrgUnitId);
}
use of com.khartec.waltz.model.application.Application in project waltz by khartec.
the class LogicalFlowDecoratorRatingsCalculator method calculate.
public Collection<LogicalFlowDecorator> calculate(Collection<LogicalFlowDecorator> decorators) {
List<LogicalFlow> flows = loadFlows(decorators).stream().filter(f -> f.target().kind() == EntityKind.APPLICATION && f.source().kind() == EntityKind.APPLICATION).collect(toList());
if (isEmpty(flows))
return Collections.emptyList();
List<Application> targetApps = loadTargetApplications(flows);
List<DataType> dataTypes = dataTypeDao.getAll();
Map<Long, DataType> typesById = indexById(dataTypes);
Map<Long, LogicalFlow> flowsById = indexById(flows);
Map<Long, Application> targetAppsById = indexById(targetApps);
AuthoritativeSourceResolver resolver = createResolver(targetApps);
return decorators.stream().map(decorator -> {
try {
if (decorator.decoratorEntity().kind() != EntityKind.DATA_TYPE) {
return decorator;
} else {
AuthoritativenessRating rating = lookupRating(typesById, flowsById, targetAppsById, resolver, decorator);
return ImmutableLogicalFlowDecorator.copyOf(decorator).withRating(rating);
}
} catch (Exception e) {
LOG.warn("Failed to calculate rating for decorator: {}, reason: {}", decorator, e.getMessage());
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toSet());
}
Aggregations