Search in sources :

Example 1 with ListRoute

use of org.finos.waltz.web.ListRoute in project waltz by khartec.

the class PhysicalSpecDefinitionEndpoint method register.

@Override
public void register() {
    String findForSpecificationPath = WebUtilities.mkPath(BASE_URL, "specification", ":id");
    String findBySelectorPath = WebUtilities.mkPath(BASE_URL, "selector");
    String createPath = WebUtilities.mkPath(BASE_URL, "specification", ":id");
    String updateStatusPath = WebUtilities.mkPath(BASE_URL, "specification", ":id", "status");
    String deletePath = WebUtilities.mkPath(BASE_URL, "specification", ":id");
    ListRoute<PhysicalSpecDefinition> findForSpecificationRoute = (req, res) -> specDefinitionService.findForSpecification(WebUtilities.getId(req));
    ListRoute<PhysicalSpecDefinition> findBySelectorRoute = (req, res) -> specDefinitionService.findBySelector(WebUtilities.readIdSelectionOptionsFromBody(req));
    DatumRoute<Long> createRoute = (req, res) -> {
        WebUtilities.requireRole(userRoleService, req, SystemRole.LOGICAL_DATA_FLOW_EDITOR);
        PhysicalSpecDefinitionChangeCommand physicalSpecDefinitionChangeCommand = WebUtilities.readBody(req, PhysicalSpecDefinitionChangeCommand.class);
        long physicalSpecificationId = WebUtilities.getId(req);
        Set<String> existingVersions = map(specDefinitionService.findForSpecification(physicalSpecificationId), d -> d.version());
        if (existingVersions.contains(physicalSpecDefinitionChangeCommand.version())) {
            throw new DuplicateKeyException("Cannot create physical specification definition with version that already exists");
        }
        return specDefinitionService.create(WebUtilities.getUsername(req), physicalSpecificationId, physicalSpecDefinitionChangeCommand);
    };
    DatumRoute<Boolean> updateStatusRoute = (req, res) -> {
        WebUtilities.requireRole(userRoleService, req, SystemRole.LOGICAL_DATA_FLOW_EDITOR);
        return specDefinitionService.updateStatus(WebUtilities.getUsername(req), WebUtilities.getId(req), WebUtilities.readBody(req, ReleaseLifecycleStatusChangeCommand.class));
    };
    DatumRoute<Integer> deleteRoute = (req, res) -> {
        WebUtilities.requireRole(userRoleService, req, SystemRole.LOGICAL_DATA_FLOW_EDITOR);
        return specDefinitionService.delete(WebUtilities.getUsername(req), WebUtilities.getId(req));
    };
    EndpointUtilities.getForList(findForSpecificationPath, findForSpecificationRoute);
    EndpointUtilities.postForList(findBySelectorPath, findBySelectorRoute);
    EndpointUtilities.postForDatum(createPath, createRoute);
    EndpointUtilities.putForDatum(updateStatusPath, updateStatusRoute);
    EndpointUtilities.deleteForDatum(deletePath, deleteRoute);
}
Also used : ListRoute(org.finos.waltz.web.ListRoute) Endpoint(org.finos.waltz.web.endpoints.Endpoint) DatumRoute(org.finos.waltz.web.DatumRoute) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) PhysicalSpecDefinition(org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinition) ReleaseLifecycleStatusChangeCommand(org.finos.waltz.model.ReleaseLifecycleStatusChangeCommand) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) UserRoleService(org.finos.waltz.service.user.UserRoleService) PhysicalSpecDefinitionService(org.finos.waltz.service.physical_specification_definition.PhysicalSpecDefinitionService) Service(org.springframework.stereotype.Service) WebUtilities(org.finos.waltz.web.WebUtilities) SystemRole(org.finos.waltz.model.user.SystemRole) DuplicateKeyException(org.finos.waltz.common.exception.DuplicateKeyException) PhysicalSpecDefinitionChangeCommand(org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinitionChangeCommand) EndpointUtilities(org.finos.waltz.web.endpoints.EndpointUtilities) PhysicalSpecDefinitionChangeCommand(org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinitionChangeCommand) Set(java.util.Set) DuplicateKeyException(org.finos.waltz.common.exception.DuplicateKeyException) PhysicalSpecDefinition(org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinition)

Example 2 with ListRoute

use of org.finos.waltz.web.ListRoute in project waltz by khartec.

the class AttestationInstanceEndpoint method register.

@Override
public void register() {
    String attestInstancePath = mkPath(BASE_URL, "attest", ":id");
    String attestEntityForUserPath = mkPath(BASE_URL, "attest-entity");
    String findByEntityRefPath = mkPath(BASE_URL, "entity", ":kind", ":id");
    String findByRunIdPath = mkPath(BASE_URL, "run", ":id");
    String findUnattestedByUserPath = mkPath(BASE_URL, "unattested", "user");
    String findAllByUserPath = mkPath(BASE_URL, "all", "user");
    String findHistoricalForPendingByUserPath = mkPath(BASE_URL, "historical", "user");
    String findPersonsByInstancePath = mkPath(BASE_URL, ":id", "person");
    String findBySelectorPath = mkPath(BASE_URL, "selector");
    String findLatestMeasurableAttestationsPath = mkPath(BASE_URL, "latest", "measurable-category", "entity", ":kind", ":id");
    String findApplicationAttestationInstancesForKindAndSelectorPath = mkPath(BASE_URL, "applications", "attested-entity", ":kind", ":id");
    String findApplicationAttestationSummaryForSelectorPath = mkPath(BASE_URL, "app-summary");
    String cleanupOrphansPath = mkPath(BASE_URL, "cleanup-orphans");
    String reassignRecipientsPath = mkPath(BASE_URL, "reassign-recipients");
    String getCountsOfRecipientsToReassignPath = mkPath(BASE_URL, "reassign-counts");
    DatumRoute<Boolean> attestInstanceRoute = (req, res) -> attestationInstanceService.attestInstance(getId(req), getUsername(req));
    ListRoute<AttestationInstance> findByEntityRefRoute = (req, res) -> attestationInstanceService.findByEntityReference(getEntityReference(req));
    ListRoute<AttestationInstance> findUnattestedByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), true);
    ListRoute<AttestationInstance> findAllByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), false);
    ListRoute<AttestationInstance> findHistoricalForPendingByRecipientRoute = (req, res) -> attestationInstanceService.findHistoricalForPendingByUserId(getUsername(req));
    ListRoute<AttestationInstance> findByRunIdRoute = (req, res) -> attestationInstanceService.findByRunId(getId(req));
    ListRoute<Person> findPersonsByInstanceRoute = (request, response) -> {
        long id = Long.valueOf(request.params("id"));
        return attestationInstanceService.findPersonsByInstanceId(id);
    };
    ListRoute<AttestationInstance> findBySelectorRoute = ((request, response) -> attestationInstanceService.findByIdSelector(readIdSelectionOptionsFromBody(request)));
    ListRoute<LatestMeasurableAttestationInfo> findLatestMeasurableAttestationsRoute = ((request, response) -> attestationInstanceService.findLatestMeasurableAttestations(getEntityReference(request)));
    ListRoute<ApplicationAttestationInstanceSummary> findApplicationAttestationInstancesForKindAndSelectorRoute = ((request, response) -> {
        EntityKind attestedKind = getKind(request);
        Long attestedId = StringUtilities.parseLong(request.params("id"), null);
        ApplicationAttestationInstanceInfo applicationAttestationInstanceInfo = readBody(request, ApplicationAttestationInstanceInfo.class);
        return attestationInstanceService.findApplicationAttestationInstancesForKindAndSelector(attestedKind, attestedId, applicationAttestationInstanceInfo);
    });
    ListRoute<ApplicationAttestationSummaryCounts> findApplicationAttestationSummaryForSelectorRoute = ((request, response) -> attestationInstanceService.findAttestationInstanceSummaryForSelector(readBody(request, ApplicationAttestationInstanceInfo.class)));
    DatumRoute<Boolean> attestEntityForUserRoute = (req, res) -> attestationInstanceService.attestForEntity(getUsername(req), readCreateCommand(req));
    postForDatum(attestInstancePath, attestInstanceRoute);
    postForDatum(attestEntityForUserPath, attestEntityForUserRoute);
    getForList(findByEntityRefPath, findByEntityRefRoute);
    getForList(findUnattestedByUserPath, findUnattestedByRecipientRoute);
    getForList(findAllByUserPath, findAllByRecipientRoute);
    getForList(findHistoricalForPendingByUserPath, findHistoricalForPendingByRecipientRoute);
    getForList(findByRunIdPath, findByRunIdRoute);
    getForList(findPersonsByInstancePath, findPersonsByInstanceRoute);
    getForList(findLatestMeasurableAttestationsPath, findLatestMeasurableAttestationsRoute);
    postForList(findBySelectorPath, findBySelectorRoute);
    postForList(findApplicationAttestationInstancesForKindAndSelectorPath, findApplicationAttestationInstancesForKindAndSelectorRoute);
    postForList(findApplicationAttestationSummaryForSelectorPath, findApplicationAttestationSummaryForSelectorRoute);
    getForDatum(cleanupOrphansPath, this::cleanupOrphansRoute);
    postForDatum(reassignRecipientsPath, this::reassignRecipientsRoute);
    getForDatum(getCountsOfRecipientsToReassignPath, this::getCountsOfRecipientsToReassign);
}
Also used : ListRoute(org.finos.waltz.web.ListRoute) Logger(org.slf4j.Logger) Endpoint(org.finos.waltz.web.endpoints.Endpoint) EntityKind(org.finos.waltz.model.EntityKind) DatumRoute(org.finos.waltz.web.DatumRoute) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Person(org.finos.waltz.model.person.Person) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) UserRoleService(org.finos.waltz.service.user.UserRoleService) Service(org.springframework.stereotype.Service) Request(spark.Request) AttestationInstanceService(org.finos.waltz.service.attestation.AttestationInstanceService) WebUtilities(org.finos.waltz.web.WebUtilities) SystemRole(org.finos.waltz.model.user.SystemRole) Response(spark.Response) org.finos.waltz.model.attestation(org.finos.waltz.model.attestation) EndpointUtilities(org.finos.waltz.web.endpoints.EndpointUtilities) StringUtilities(org.finos.waltz.common.StringUtilities) Person(org.finos.waltz.model.person.Person) EntityKind(org.finos.waltz.model.EntityKind)

Example 3 with ListRoute

use of org.finos.waltz.web.ListRoute in project waltz by khartec.

the class UserAgentInfoEndpoint method register.

@Override
public void register() {
    String findForUserPath = WebUtilities.mkPath(BASE_URL, "user", ":userName");
    String recordLoginPath = WebUtilities.mkPath(BASE_URL);
    ListRoute<UserAgentInfo> findForUserRoute = ((request, response) -> {
        String userName = request.params("userName");
        String limitStr = request.queryParams("limit");
        int limit = limitStr == null || limitStr.equals("") ? DEFAULT_LIMIT : Integer.parseInt(limitStr);
        return userAgentInfoService.findLoginsForUser(userName, limit);
    });
    DatumRoute<Integer> recordLoginRoute = (request, response) -> {
        BrowserInfo browserInfo = WebUtilities.readBody(request, BrowserInfo.class);
        UserAgentInfo userAgentInfo = ImmutableUserAgentInfo.builder().userName(WebUtilities.getUsername(request)).userAgent(request.userAgent()).operatingSystem(browserInfo.operatingSystem()).resolution(browserInfo.resolution()).loginTimestamp(DateTimeUtilities.nowUtc()).ipAddress(request.ip()).build();
        return userAgentInfoService.save(userAgentInfo);
    };
    EndpointUtilities.getForList(findForUserPath, findForUserRoute);
    EndpointUtilities.postForDatum(recordLoginPath, recordLoginRoute);
}
Also used : ListRoute(org.finos.waltz.web.ListRoute) UserAgentInfoService(org.finos.waltz.service.user_agent_info.UserAgentInfoService) ImmutableUserAgentInfo(org.finos.waltz.model.user_agent_info.ImmutableUserAgentInfo) Endpoint(org.finos.waltz.web.endpoints.Endpoint) DatumRoute(org.finos.waltz.web.DatumRoute) Autowired(org.springframework.beans.factory.annotation.Autowired) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) Service(org.springframework.stereotype.Service) WebUtilities(org.finos.waltz.web.WebUtilities) UserAgentInfo(org.finos.waltz.model.user_agent_info.UserAgentInfo) BrowserInfo(org.finos.waltz.web.json.BrowserInfo) EndpointUtilities(org.finos.waltz.web.endpoints.EndpointUtilities) BrowserInfo(org.finos.waltz.web.json.BrowserInfo) ImmutableUserAgentInfo(org.finos.waltz.model.user_agent_info.ImmutableUserAgentInfo) UserAgentInfo(org.finos.waltz.model.user_agent_info.UserAgentInfo) Endpoint(org.finos.waltz.web.endpoints.Endpoint)

Aggregations

Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)3 DatumRoute (org.finos.waltz.web.DatumRoute)3 ListRoute (org.finos.waltz.web.ListRoute)3 WebUtilities (org.finos.waltz.web.WebUtilities)3 Endpoint (org.finos.waltz.web.endpoints.Endpoint)3 EndpointUtilities (org.finos.waltz.web.endpoints.EndpointUtilities)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 SystemRole (org.finos.waltz.model.user.SystemRole)2 UserRoleService (org.finos.waltz.service.user.UserRoleService)2 IOException (java.io.IOException)1 Set (java.util.Set)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)1 StringUtilities (org.finos.waltz.common.StringUtilities)1 DuplicateKeyException (org.finos.waltz.common.exception.DuplicateKeyException)1 EntityKind (org.finos.waltz.model.EntityKind)1 ReleaseLifecycleStatusChangeCommand (org.finos.waltz.model.ReleaseLifecycleStatusChangeCommand)1 org.finos.waltz.model.attestation (org.finos.waltz.model.attestation)1 Person (org.finos.waltz.model.person.Person)1