use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class ChangeUnitViewService method findPhysicalFlowChangeUnitsByChangeSetId.
public Set<PhysicalFlowChangeUnitViewItem> findPhysicalFlowChangeUnitsByChangeSetId(long changeSetId) {
IdSelectionOptions idSelectionOptions = mkOptsForAllLifecycleStates(mkRef(EntityKind.CHANGE_SET, changeSetId), HierarchyQueryScope.EXACT);
Collection<PhysicalFlow> physicalFlows = physicalFlowService.findBySelector(idSelectionOptions);
Collection<PhysicalSpecification> physicalSpecs = physicalSpecificationService.findByIds(map(physicalFlows, PhysicalFlow::specificationId));
// TODO: Move to a logical flow selector based upon change set #5626
Collection<LogicalFlow> logicalFlows = logicalFlowService.findAllByFlowIds(map(physicalFlows, PhysicalFlow::logicalFlowId));
List<AssessmentRating> assessmentRatings = assessmentRatingService.findByTargetKindForRelatedSelector(EntityKind.CHANGE_UNIT, idSelectionOptions);
Map<Long, RatingSchemeItem> ratingSchemeItemsById = indexBy(ratingSchemeService.getAllRatingSchemeItems(), item -> item.id().get());
Map<Long, PhysicalFlow> physicalFlowsById = indexBy(physicalFlows, flow -> flow.id().get());
Map<Long, LogicalFlow> logicalFlowsById = indexBy(logicalFlows, flow -> flow.id().get());
Map<Long, PhysicalSpecification> specsById = indexBy(physicalSpecs, spec -> spec.id().get());
Map<Long, Collection<AssessmentRating>> assessmentRatingsByEntityId = groupBy(rating -> rating.entityReference().id(), assessmentRatings);
List<ChangeUnit> changeUnits = changeUnitService.findByChangeSetId(changeSetId);
return changeUnits.stream().filter(cu -> cu.subjectEntity().kind().equals(EntityKind.PHYSICAL_FLOW)).map(cu -> {
PhysicalFlow physicalFlow = physicalFlowsById.get(cu.subjectEntity().id());
PhysicalSpecification spec = specsById.get(physicalFlow.specificationId());
LogicalFlow logicalFlow = logicalFlowsById.get(physicalFlow.logicalFlowId());
Long changeUnitId = cu.id().get();
Collection<AssessmentRating> assessmentRatingsForChangeUnit = assessmentRatingsByEntityId.getOrDefault(changeUnitId, emptySet());
Set<AssessmentRatingDetail> assessmentRatingDetailForChangeUnit = map(assessmentRatingsForChangeUnit, rating -> mkAssessmentDefinitionDetail(rating, ratingSchemeItemsById.get(rating.ratingId())));
return ImmutablePhysicalFlowChangeUnitViewItem.builder().changeUnit(cu).physicalSpecification(spec).logicalFlow(logicalFlow).assessments(assessmentRatingDetailForChangeUnit).build();
}).collect(toSet());
}
use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalFlowService method copyExternalIdFromFlowAndSpecification.
private void copyExternalIdFromFlowAndSpecification(String username, EntityReference toRef, PhysicalFlow sourcePhysicalFlow) {
PhysicalFlow targetPhysicalFlow = physicalFlowDao.getById(toRef.id());
Set<String> externalIdentifiers = externalIdentifierService.findByEntityReference(toRef).stream().map(ExternalIdentifier::externalId).collect(Collectors.toSet());
sourcePhysicalFlow.externalId().filter(id -> !isEmpty(id)).ifPresent(sourceExtId -> {
if (isEmpty(targetPhysicalFlow.externalId())) {
physicalFlowDao.updateExternalId(toRef.id(), sourceExtId);
} else if (!externalIdentifiers.contains(sourceExtId)) {
externalIdentifierService.create(toRef, sourceExtId, username);
externalIdentifiers.add(sourceExtId);
}
});
PhysicalSpecification sourceSpec = physicalSpecificationService.getById(sourcePhysicalFlow.specificationId());
sourceSpec.externalId().filter(id -> !isEmpty(id)).ifPresent(sourceExtId -> {
PhysicalSpecification targetSpec = physicalSpecificationService.getById(targetPhysicalFlow.specificationId());
if (isEmpty(targetSpec.externalId())) {
targetSpec.id().ifPresent(id -> physicalSpecificationService.updateExternalId(id, sourceExtId));
} else if (!externalIdentifiers.contains(sourceExtId)) {
externalIdentifierService.create(toRef, sourceExtId, username);
}
});
}
use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalFlowGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
DSLContext dsl = getDsl(ctx);
List<PhysicalSpecification> specifications = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).fetch(PhysicalSpecificationDao.TO_DOMAIN_MAPPER);
List<String> transportKinds = dsl.select(ENUM_VALUE.KEY).from(ENUM_VALUE).where(ENUM_VALUE.TYPE.eq(EnumValueKind.TRANSPORT_KIND.dbValue())).fetch(ENUM_VALUE.KEY);
List<Tuple3<Long, Long, Long>> allLogicalFLows = dsl.select(LOGICAL_FLOW.ID, LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.TARGET_ENTITY_ID).from(LOGICAL_FLOW).fetch(r -> Tuple.tuple(r.getValue(LOGICAL_FLOW.ID), r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_ID), r.getValue(LOGICAL_FLOW.TARGET_ENTITY_ID)));
Map<Long, Collection<Long>> logicalFlowIdsBySourceApp = groupBy(t -> t.v2(), t -> t.v1(), allLogicalFLows);
final int flowBatchSize = 100000;
List<PhysicalFlowRecord> flowBatch = new ArrayList<PhysicalFlowRecord>((int) (flowBatchSize * 1.2));
for (PhysicalSpecification spec : specifications) {
Collection<Long> relatedLogicalFlowsIds = logicalFlowIdsBySourceApp.get(spec.owningEntity().id());
if (!isEmpty(relatedLogicalFlowsIds)) {
List<PhysicalFlowRecord> physicalFlowRecords = mkPhysicalFlowRecords(spec, new LinkedList<>(relatedLogicalFlowsIds), transportKinds);
flowBatch.addAll(physicalFlowRecords);
}
if (flowBatch.size() >= flowBatchSize) {
log(String.format("--- saving records: count: %s", flowBatch.size()));
dsl.batchInsert(flowBatch).execute();
flowBatch.clear();
}
}
log(String.format("--- saving records: count: %s", flowBatch.size()));
dsl.batchInsert(flowBatch).execute();
flowBatch.clear();
log("---done");
return null;
}
use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalFlowUploadService method getOrCreatePhysicalSpec.
private PhysicalSpecification getOrCreatePhysicalSpec(PhysicalFlowParsed flow, String username) {
EntityReference owner = flow.owner();
DataFormatKind format = flow.format();
String name = flow.name();
// check database
PhysicalSpecification spec = physicalSpecificationDao.getByParsedFlow(flow);
if (spec == null) {
// create
LocalDateTime now = nowUtc();
PhysicalSpecification specToAdd = ImmutablePhysicalSpecification.builder().owningEntity(owner).format(format).name(name).externalId(Optional.ofNullable(flow.specExternalId()).orElse("")).description(Optional.ofNullable(flow.specDescription()).orElse("")).lastUpdatedBy(username).lastUpdatedAt(now).provenance("waltz").created(UserTimestamp.mkForUser(username, now)).build();
Long id = physicalSpecificationDao.create(specToAdd);
spec = ImmutablePhysicalSpecification.copyOf(specToAdd).withId(id);
}
long dataTypeId = flow.dataType().id();
EntityReference specificationEntityRef = EntityReference.mkRef(EntityKind.PHYSICAL_SPECIFICATION, spec.id().get());
DataTypeDecorator existingDataType = dataTypeDecoratorService.getByEntityRefAndDataTypeId(specificationEntityRef, dataTypeId);
if (existingDataType == null) {
dataTypeDecoratorService.addDecorators(username, specificationEntityRef, fromArray(dataTypeId));
}
return spec;
}
use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalSpecificationService method markRemovedIfUnused.
public CommandResponse<PhysicalSpecificationDeleteCommand> markRemovedIfUnused(PhysicalSpecificationDeleteCommand command, String username) {
checkNotNull(command, "command cannot be null");
CommandOutcome commandOutcome = CommandOutcome.SUCCESS;
String responseMessage = null;
PhysicalSpecification specification = specificationDao.getById(command.specificationId());
if (specification == null) {
commandOutcome = CommandOutcome.FAILURE;
responseMessage = "Specification not found";
} else {
int deleteCount = specificationDao.markRemovedIfUnused(command.specificationId());
if (deleteCount == 0) {
commandOutcome = CommandOutcome.FAILURE;
responseMessage = "This specification cannot be deleted as it is being referenced by one or more physical flows";
}
}
if (commandOutcome == CommandOutcome.SUCCESS) {
logChange(username, specification.owningEntity(), String.format("Specification: %s removed", specification.name()), Operation.REMOVE);
}
return ImmutableCommandResponse.<PhysicalSpecificationDeleteCommand>builder().entityReference(EntityReference.mkRef(EntityKind.PHYSICAL_SPECIFICATION, command.specificationId())).originalCommand(command).outcome(commandOutcome).message(Optional.ofNullable(responseMessage)).build();
}
Aggregations