Search in sources :

Example 1 with PhysicalSpecification

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();
}
Also used : CommandOutcome(com.khartec.waltz.model.command.CommandOutcome) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) ImmutablePhysicalSpecification(com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow)

Example 2 with PhysicalSpecification

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();
}
Also used : CommandOutcome(com.khartec.waltz.model.command.CommandOutcome) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification)

Example 3 with PhysicalSpecification

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");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) PhysicalFlowRecord(com.khartec.waltz.schema.tables.records.PhysicalFlowRecord) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) DSLContext(org.jooq.DSLContext) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Tuple2(org.jooq.lambda.tuple.Tuple2) EntityReference(com.khartec.waltz.model.EntityReference)

Example 4 with PhysicalSpecification

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;
}
Also used : Condition(org.jooq.Condition) Record(org.jooq.Record) PHYSICAL_SPECIFICATION(com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION) PhysicalSpecificationDao.owningEntityNameField(com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao.owningEntityNameField) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) ListUtilities(com.khartec.waltz.common.ListUtilities) Autowired(org.springframework.beans.factory.annotation.Autowired) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) Condition(org.jooq.Condition) SearchUtilities.mkRelevancyComparator(com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator) List(java.util.List) PhysicalSpecificationDao(com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao) DSLContext(org.jooq.DSLContext) Optional(java.util.Optional) ImmutablePhysicalSpecification(com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SelectQuery(org.jooq.SelectQuery) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) Repository(org.springframework.stereotype.Repository) JooqUtilities.mkBasicTermSearch(com.khartec.waltz.data.JooqUtilities.mkBasicTermSearch) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) ImmutablePhysicalSpecification(com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) Record(org.jooq.Record)

Aggregations

PhysicalSpecification (com.khartec.waltz.model.physical_specification.PhysicalSpecification)4 ListUtilities.newArrayList (com.khartec.waltz.common.ListUtilities.newArrayList)2 CommandOutcome (com.khartec.waltz.model.command.CommandOutcome)2 ImmutablePhysicalSpecification (com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification)2 DSLContext (org.jooq.DSLContext)2 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1 JooqUtilities.mkBasicTermSearch (com.khartec.waltz.data.JooqUtilities.mkBasicTermSearch)1 SearchUtilities.mkRelevancyComparator (com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator)1 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)1 PhysicalSpecificationDao (com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao)1 PhysicalSpecificationDao.owningEntityNameField (com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao.owningEntityNameField)1 EntityReference (com.khartec.waltz.model.EntityReference)1 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)1 ImmutableLogicalFlow (com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow)1 LogicalFlow (com.khartec.waltz.model.logical_flow.LogicalFlow)1 PHYSICAL_SPECIFICATION (com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION)1 PhysicalFlowRecord (com.khartec.waltz.schema.tables.records.PhysicalFlowRecord)1 List (java.util.List)1 Optional (java.util.Optional)1