Search in sources :

Example 1 with DataFormatKind

use of org.finos.waltz.model.physical_specification.DataFormatKind in project waltz by khartec.

the class PhysicalFlowUploadService method validateCommand.

// //////////////////// PRIVATE //////////////////////
// ///////////////////////////////////////////////////
private PhysicalFlowUploadCommandResponse validateCommand(Map<String, Actor> actorsByName, Map<String, Application> applicationsByAssetCode, Map<String, DataType> dataTypeMap, Aliases<TransportKindValue> transportAliases, PhysicalFlowUploadCommand cmd) {
    checkNotNull(cmd, "cmd cannot be null");
    Map<String, String> errors = new HashMap<>();
    // resolve entity refs - source, target, owner
    EntityReference source = getNodeRefByString(actorsByName, applicationsByAssetCode, cmd.source());
    EntityReference target = getNodeRefByString(actorsByName, applicationsByAssetCode, cmd.target());
    EntityReference owner = getNodeRefByString(actorsByName, applicationsByAssetCode, cmd.owner());
    EntityReference dataType = getDataTypeByString(dataTypeMap, cmd.dataType());
    if (source == null) {
        errors.put("source", String.format("%s not found", cmd.source()));
    }
    if (target == null) {
        errors.put("target", String.format("%s not found", cmd.target()));
    }
    if (owner == null) {
        errors.put("owner", String.format("%s not found", cmd.owner()));
    }
    if (dataType == null) {
        errors.put("dataType", String.format("%s not found", cmd.dataType()));
    }
    // resolve enums - format, frequency, transport, criticality
    DataFormatKind format = DataFormatKind.parse(cmd.format(), (s) -> null);
    if (format == null) {
        errors.put("format", String.format("%s is not a recognised value", cmd.format()));
    }
    FrequencyKind frequency = FrequencyKind.parse(cmd.frequency(), (s) -> null);
    if (frequency == null) {
        errors.put("frequency", String.format("%s is not a recognised value", cmd.frequency()));
    }
    TransportKindValue transport = transportAliases.lookup(cmd.transport()).orElseGet(() -> {
        errors.put("transport", String.format("%s is not a recognised value", cmd.transport()));
        return null;
    });
    Criticality criticality = Criticality.parse(cmd.criticality(), (s) -> null);
    if (criticality == null) {
        errors.put("criticality", String.format("%s is not a recognised value", cmd.criticality()));
    }
    // check for nulls or duplicates in other fields
    if (isEmpty(cmd.name())) {
        errors.put("name", "name not provided");
    }
    Integer basisOffset = parseBasisOffset(cmd.basisOffset());
    if (basisOffset == null) {
        errors.put("basisOffset", String.format("%s is not a recognised value, expect this to be a number", cmd.basisOffset()));
    }
    ImmutablePhysicalFlowParsed parsedFlow = ImmutablePhysicalFlowParsed.builder().source(source).target(target).owner(owner).name(cmd.name()).format(format).specDescription(cmd.specDescription()).specExternalId(cmd.specExternalId()).frequency(frequency).transport(transport).criticality(criticality).description(cmd.description()).externalId(cmd.externalId()).basisOffset(basisOffset).dataType(dataType).build();
    return ImmutablePhysicalFlowUploadCommandResponse.builder().parsedFlow(parsedFlow).errors(errors).originalCommand(cmd).outcome(errors.size() > 0 ? CommandOutcome.FAILURE : CommandOutcome.SUCCESS).build();
}
Also used : HashMap(java.util.HashMap) DataFormatKind(org.finos.waltz.model.physical_specification.DataFormatKind) EntityReference(org.finos.waltz.model.EntityReference) Criticality(org.finos.waltz.model.Criticality)

Example 2 with DataFormatKind

use of org.finos.waltz.model.physical_specification.DataFormatKind 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;
}
Also used : LocalDateTime(java.time.LocalDateTime) ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) DataFormatKind(org.finos.waltz.model.physical_specification.DataFormatKind) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference)

Aggregations

EntityReference (org.finos.waltz.model.EntityReference)2 DataFormatKind (org.finos.waltz.model.physical_specification.DataFormatKind)2 LocalDateTime (java.time.LocalDateTime)1 HashMap (java.util.HashMap)1 Criticality (org.finos.waltz.model.Criticality)1 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)1 ImmutablePhysicalSpecification (org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification)1 PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)1