Search in sources :

Example 11 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class EntityTagDao method updateTags.

public int[] updateTags(EntityReference ref, Collection<String> tags, String username) {
    LOG.info("Updating tags for entity ref: {}, tags: {} ", ref, tags);
    dsl.delete(ENTITY_TAG).where(ENTITY_TAG.ENTITY_ID.eq(ref.id())).and(ENTITY_TAG.ENTITY_KIND.eq(ref.kind().name())).execute();
    List<EntityTagRecord> records = tags.stream().map(t -> {
        EntityTagRecord record = new EntityTagRecord();
        record.setEntityId(ref.id());
        record.setEntityKind(ref.kind().name());
        record.setTag(t);
        record.setLastUpdatedAt(Timestamp.valueOf(DateTimeUtilities.nowUtc()));
        record.setLastUpdatedBy(username);
        record.setProvenance("waltz");
        return record;
    }).collect(Collectors.toList());
    return dsl.batchInsert(records).execute();
}
Also used : Logger(org.slf4j.Logger) Collections.emptyList(java.util.Collections.emptyList) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityReference(com.khartec.waltz.model.EntityReference) Field(org.jooq.Field) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) Collectors(java.util.stream.Collectors) DateTimeUtilities(com.khartec.waltz.common.DateTimeUtilities) EntityKind(com.khartec.waltz.model.EntityKind) List(java.util.List) EntityNameUtilities(com.khartec.waltz.data.EntityNameUtilities) DSLContext(org.jooq.DSLContext) StringUtilities.isEmpty(com.khartec.waltz.common.StringUtilities.isEmpty) ENTITY_TAG(com.khartec.waltz.schema.tables.EntityTag.ENTITY_TAG) Repository(org.springframework.stereotype.Repository) EntityTagRecord(com.khartec.waltz.schema.tables.records.EntityTagRecord) EntityTagRecord(com.khartec.waltz.schema.tables.records.EntityTagRecord)

Example 12 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class PhysicalFlowUploadService method validateCommand.

private PhysicalFlowValidateCommandResponse validateCommand(PhysicalFlowValidateCommand cmd) {
    checkNotNull(cmd, "cmd cannot be null");
    Map<String, String> errors = new HashMap<>();
    // resolve entity refs - source, target, owner
    EntityReference source = getEntityRefByString(cmd.source());
    EntityReference target = getEntityRefByString(cmd.target());
    EntityReference owner = getEntityRefByString(cmd.owner());
    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()));
    }
    // 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()));
    }
    TransportKind transport = TransportKind.parse(cmd.transport(), (s) -> null);
    if (transport == null) {
        errors.put("transport", String.format("%s is not a recognised value", cmd.transport()));
    }
    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).build();
    return ImmutablePhysicalFlowValidateCommandResponse.builder().parsedFlow(parsedFlow).errors(errors).originalCommand(cmd).outcome(errors.size() > 0 ? CommandOutcome.FAILURE : CommandOutcome.SUCCESS).build();
}
Also used : HashMap(java.util.HashMap) DataFormatKind(com.khartec.waltz.model.physical_specification.DataFormatKind) EntityReference(com.khartec.waltz.model.EntityReference) Criticality(com.khartec.waltz.model.Criticality)

Example 13 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class AuthoritativeSourceEndpoint method calculateConsumersForDataTypeIdSelectorRoute.

private List<Entry<EntityReference, Collection<EntityReference>>> calculateConsumersForDataTypeIdSelectorRoute(Request request, Response response) throws IOException {
    IdSelectionOptions options = readIdSelectionOptionsFromBody(request);
    Map<EntityReference, Collection<EntityReference>> result = authoritativeSourceService.calculateConsumersForDataTypeIdSelector(options);
    return simplifyMapToList(result);
}
Also used : EntityReference(com.khartec.waltz.model.EntityReference) Collection(java.util.Collection) IdSelectionOptions(com.khartec.waltz.model.IdSelectionOptions)

Example 14 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class BookmarksEndpoint method register.

@Override
public void register() {
    get(mkPath(BASE_URL, ":kind", ":id"), (request, response) -> {
        response.type(TYPE_JSON);
        EntityReference ref = getEntityReference(request);
        return bookmarkService.findByReference(ref);
    }, transformer);
    post(mkPath(BASE_URL), (request, response) -> {
        requireRole(userRoleService, request, Role.BOOKMARK_EDITOR);
        response.type(TYPE_JSON);
        Bookmark bookmark = readBody(request, Bookmark.class);
        LOG.info("Saving bookmark: " + bookmark);
        boolean isUpdate = bookmark.id().isPresent();
        return isUpdate ? bookmarkService.update(bookmark, getUsername(request)) : bookmarkService.create(bookmark, getUsername(request));
    }, transformer);
    delete(mkPath(BASE_URL, ":id"), (request, response) -> {
        requireRole(userRoleService, request, Role.BOOKMARK_EDITOR);
        response.type(TYPE_JSON);
        long bookmarkId = getId(request);
        Bookmark bookmark = bookmarkService.getById(bookmarkId);
        if (bookmark == null) {
            LOG.warn("Attempt made to delete non-existent bookmark: " + bookmarkId);
            return false;
        }
        LOG.info("Deleting bookmark: " + bookmark);
        return bookmarkService.deleteById(bookmark, getUsername(request));
    }, transformer);
}
Also used : Bookmark(com.khartec.waltz.model.bookmark.Bookmark) EntityReference(com.khartec.waltz.model.EntityReference)

Example 15 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class LogicalFlowEndpoint method findBySourceAndTargetsRoute.

private List<LogicalFlow> findBySourceAndTargetsRoute(Request request, Response response) throws IOException {
    List list = readBody(request, List.class);
    List<Tuple2<EntityReference, EntityReference>> sourcesAndTargets = (List<Tuple2<EntityReference, EntityReference>>) list.stream().map(t -> {
        Map map = (Map) t;
        Map source = (Map) map.get("source");
        Map target = (Map) map.get("target");
        EntityReference sourceRef = EntityReference.mkRef(source);
        EntityReference targetRef = EntityReference.mkRef(target);
        return Tuple.tuple(sourceRef, targetRef);
    }).collect(Collectors.toList());
    return logicalFlowService.findBySourceAndTargetEntityReferences(sourcesAndTargets);
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) EntityReference(com.khartec.waltz.model.EntityReference) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

EntityReference (com.khartec.waltz.model.EntityReference)33 EntityKind (com.khartec.waltz.model.EntityKind)11 DSLContext (org.jooq.DSLContext)9 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)9 List (java.util.List)8 ListUtilities.newArrayList (com.khartec.waltz.common.ListUtilities.newArrayList)6 Collection (java.util.Collection)6 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)4 SetUtilities (com.khartec.waltz.common.SetUtilities)4 IdSelectionOptions (com.khartec.waltz.model.IdSelectionOptions)4 LogicalFlow (com.khartec.waltz.model.logical_flow.LogicalFlow)4 LOGICAL_FLOW (com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW)4 DIConfiguration (com.khartec.waltz.service.DIConfiguration)4 EntityReference.mkRef (com.khartec.waltz.model.EntityReference.mkRef)3 ImmutableEntityReference (com.khartec.waltz.model.ImmutableEntityReference)3 Application (com.khartec.waltz.model.application.Application)3 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)3 LogicalFlowService (com.khartec.waltz.service.logical_flow.LogicalFlowService)3