use of com.khartec.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalFlowService method delete.
public PhysicalFlowDeleteCommandResponse delete(PhysicalFlowDeleteCommand command, String username) {
checkNotNull(command, "command cannot be null");
PhysicalFlow physicalFlow = physicalFlowDao.getById(command.flowId());
LogicalFlow logicalFlow = logicalFlowService.getById(physicalFlow.logicalFlowId());
CommandOutcome commandOutcome = CommandOutcome.SUCCESS;
String responseMessage = null;
boolean isSpecificationUnused = false;
if (physicalFlow == null) {
commandOutcome = CommandOutcome.FAILURE;
responseMessage = "Flow not found";
} else {
int deleteCount = physicalFlowDao.delete(command.flowId());
if (deleteCount == 0) {
commandOutcome = CommandOutcome.FAILURE;
responseMessage = "This flow cannot be deleted as it is being used in a lineage";
} else {
isSpecificationUnused = !physicalSpecificationDao.isUsed(physicalFlow.specificationId());
}
}
// log changes against source and target entities
if (commandOutcome == CommandOutcome.SUCCESS) {
PhysicalSpecification specification = physicalSpecificationDao.getById(physicalFlow.specificationId());
logChange(username, logicalFlow.source(), String.format("Physical flow: %s, from: %s, to: %s removed.", specification.name(), safeName(logicalFlow.source()), safeName(logicalFlow.target())), Operation.REMOVE);
logChange(username, logicalFlow.target(), String.format("Physical flow: %s, from: %s removed.", specification.name(), safeName(logicalFlow.source())), Operation.REMOVE);
logChange(username, logicalFlow.source(), String.format("Physical flow: %s, to: %s removed.", specification.name(), safeName(logicalFlow.target())), Operation.REMOVE);
}
return ImmutablePhysicalFlowDeleteCommandResponse.builder().originalCommand(command).entityReference(mkRef(PHYSICAL_FLOW, command.flowId())).outcome(commandOutcome).message(Optional.ofNullable(responseMessage)).isSpecificationUnused(isSpecificationUnused).build();
}
use of com.khartec.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalSpecificationService method delete.
public CommandResponse<PhysicalSpecificationDeleteCommand> delete(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.delete(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();
}
use of com.khartec.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalFlowGenerator method main.
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
List<PhysicalSpecification> specifications = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).fetch(PhysicalSpecificationDao.TO_DOMAIN_MAPPER);
List<Tuple2<Long, EntityReference>> allLogicalFLows = dsl.select(LOGICAL_FLOW.ID, LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.SOURCE_ENTITY_KIND).from(LOGICAL_FLOW).fetch(r -> Tuple.tuple(r.getValue(LOGICAL_FLOW.ID), mkRef(EntityKind.valueOf(r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_KIND)), r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_ID))));
Map<EntityReference, Collection<Long>> flowIdsBySource = groupBy(t -> t.v2(), t -> t.v1(), allLogicalFLows);
System.out.println("---removing demo records");
dsl.deleteFrom(PHYSICAL_FLOW).where(PHYSICAL_FLOW.PROVENANCE.eq(provenance)).execute();
final int flowBatchSize = 100000;
List<PhysicalFlowRecord> flowBatch = new ArrayList<PhysicalFlowRecord>((int) (flowBatchSize * 1.2));
for (PhysicalSpecification spec : specifications) {
Collection<Long> flowIds = flowIdsBySource.get(spec.owningEntity());
if (!isEmpty(flowIds)) {
List<PhysicalFlowRecord> physicalFlowRecords = mkPhysicalFlowRecords(spec, new LinkedList<>(flowIds));
flowBatch.addAll(physicalFlowRecords);
}
if (flowBatch.size() >= flowBatchSize) {
System.out.println(String.format("--- saving records: count: %s", flowBatch.size()));
dsl.batchInsert(flowBatch).execute();
flowBatch.clear();
}
}
System.out.println(String.format("--- saving records: count: %s", flowBatch.size()));
dsl.batchInsert(flowBatch).execute();
flowBatch.clear();
System.out.println("---done");
}
use of com.khartec.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalSpecificationSearchDao method search.
public List<PhysicalSpecification> search(String termsStr, EntitySearchOptions options) {
List<String> terms = mkTerms(termsStr);
if (terms.isEmpty()) {
return newArrayList();
}
Condition likeName = mkBasicTermSearch(PHYSICAL_SPECIFICATION.NAME, terms);
Condition likeDesc = mkBasicTermSearch(PHYSICAL_SPECIFICATION.DESCRIPTION, terms);
SelectQuery<Record> query = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).where(likeName).or(likeDesc).orderBy(PHYSICAL_SPECIFICATION.NAME).limit(options.limit()).getQuery();
List<PhysicalSpecification> results = query.fetch(r -> {
PhysicalSpecification spec = PhysicalSpecificationDao.TO_DOMAIN_MAPPER.map(r);
String updatedDesc = String.format("%s %s", Optional.ofNullable(r.getValue(owningEntityNameField)).map(owner -> String.format("(%s)", owner)).orElse(""), spec.description());
return ImmutablePhysicalSpecification.copyOf(spec).withDescription(updatedDesc);
});
results.sort(mkRelevancyComparator(ps -> ps.name(), terms.get(0)));
return results;
}
Aggregations