Search in sources :

Example 1 with ObjectFactory

use of org.mapstruct.ObjectFactory in project scm-review-plugin by scm-manager.

the class GlobalConfigMapper method createForGlobal.

@ObjectFactory
GlobalPullRequestConfigDto createForGlobal(@Context UriInfo uriInfo) {
    LinkBuilder linkBuilder = new LinkBuilder(uriInfo::getBaseUri, GlobalConfigResource.class);
    Links.Builder halLinks = new Links.Builder();
    halLinks.self(linkBuilder.method("getGlobalConfig").parameters().href());
    if (PermissionCheck.mayWriteGlobalConfig()) {
        halLinks.single(Link.link("update", linkBuilder.method("setGlobalConfig").parameters().href()));
    }
    return new GlobalPullRequestConfigDto(halLinks.build());
}
Also used : LinkBuilder(sonia.scm.api.v2.resources.LinkBuilder) LinkBuilder(sonia.scm.api.v2.resources.LinkBuilder) Links(de.otto.edison.hal.Links) ObjectFactory(org.mapstruct.ObjectFactory)

Example 2 with ObjectFactory

use of org.mapstruct.ObjectFactory in project scm-review-plugin by scm-manager.

the class RepositoryConfigMapper method createForRepository.

@ObjectFactory
PullRequestConfigDto createForRepository(@Context Repository repository, @Context UriInfo uriInfo) {
    LinkBuilder linkBuilder = new LinkBuilder(uriInfo::getBaseUri, RepositoryConfigResource.class);
    Links links = new Links.Builder().self(linkBuilder.method("getRepositoryConfig").parameters(repository.getNamespace(), repository.getName()).href()).single(Link.link("update", linkBuilder.method("setRepositoryConfig").parameters(repository.getNamespace(), repository.getName()).href())).build();
    return new PullRequestConfigDto(links);
}
Also used : LinkBuilder(sonia.scm.api.v2.resources.LinkBuilder) Links(de.otto.edison.hal.Links) ObjectFactory(org.mapstruct.ObjectFactory)

Example 3 with ObjectFactory

use of org.mapstruct.ObjectFactory in project scm-review-plugin by scm-manager.

the class GlobalEngineConfigMapper method create.

@ObjectFactory
GlobalEngineConfigDto create(@Context UriInfo uriInfo) {
    final Links.Builder linksBuilder = new Links.Builder();
    PullRequestResourceLinks.WorkflowEngineGlobalConfigLinks workflowEngineGlobalConfigLinks = new PullRequestResourceLinks(uriInfo::getBaseUri).workflowEngineGlobalConfigLinks();
    linksBuilder.self(workflowEngineGlobalConfigLinks.getConfig());
    if (PermissionCheck.mayConfigureGlobalWorkflowConfig()) {
        linksBuilder.single(link("update", workflowEngineGlobalConfigLinks.setConfig()));
    }
    if (PermissionCheck.mayReadGlobalWorkflowConfig() || PermissionCheck.mayConfigureGlobalWorkflowConfig()) {
        linksBuilder.single(link("availableRules", workflowEngineGlobalConfigLinks.availableRules()));
    }
    return new GlobalEngineConfigDto(linksBuilder.build());
}
Also used : Links(de.otto.edison.hal.Links) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) ObjectFactory(org.mapstruct.ObjectFactory)

Example 4 with ObjectFactory

use of org.mapstruct.ObjectFactory in project scm-review-plugin by scm-manager.

the class PullRequestMapper method createDto.

@ObjectFactory
PullRequestDto createDto(PullRequest pullRequest, @Context Repository repository) {
    String namespace = repository.getNamespace();
    String name = repository.getName();
    String pullRequestId = pullRequest.getId();
    Links.Builder linksBuilder = linkingTo().self(pullRequestResourceLinks.pullRequest().self(namespace, name, pullRequestId));
    linksBuilder.single(link("comments", pullRequestResourceLinks.pullRequestComments().all(namespace, name, pullRequestId)));
    linksBuilder.single(link("events", pullRequestResourceLinks.pullRequest().events(namespace, name, pullRequestId)));
    if (PermissionCheck.mayComment(repository) && CurrentUserResolver.getCurrentUser() != null) {
        if (pullRequest.getStatus() == PullRequestStatus.OPEN) {
            if (pullRequestService.hasUserApproved(repository, pullRequest.getId())) {
                linksBuilder.single(link("disapprove", pullRequestResourceLinks.pullRequest().disapprove(namespace, name, pullRequestId)));
            } else {
                linksBuilder.single(link("approve", pullRequestResourceLinks.pullRequest().approve(namespace, name, pullRequestId)));
            }
        }
        if (!Strings.isNullOrEmpty(CurrentUserResolver.getCurrentUser().getMail())) {
            linksBuilder.single(link("subscription", pullRequestResourceLinks.pullRequest().subscription(namespace, name, pullRequestId)));
        }
    }
    if (PermissionCheck.mayModifyPullRequest(repository, pullRequest)) {
        linksBuilder.single(link("update", pullRequestResourceLinks.pullRequest().update(namespace, name, pullRequestId)));
    }
    if (PermissionCheck.mayMerge(repository) && pullRequest.getStatus() == PullRequestStatus.OPEN) {
        linksBuilder.single(link("reject", pullRequestResourceLinks.pullRequest().reject(namespace, name, pullRequestId)));
        if (RepositoryPermissions.push(repository).isPermitted() && pullRequest.getStatus() == PullRequestStatus.OPEN) {
            linksBuilder.single(link("mergeCheck", pullRequestResourceLinks.mergeLinks().check(namespace, name, pullRequest.getId())));
            linksBuilder.single(link("mergeConflicts", pullRequestResourceLinks.mergeLinks().conflicts(namespace, name, pullRequest.getId())));
            linksBuilder.single(link("defaultCommitMessage", pullRequestResourceLinks.mergeLinks().createDefaultCommitMessage(namespace, name, pullRequest.getId())));
            linksBuilder.single(link("mergeStrategyInfo", pullRequestResourceLinks.mergeLinks().getMergeStrategyInfo(namespace, name, pullRequestId)));
            appendMergeStrategyLinks(linksBuilder, repository, pullRequest);
        }
    }
    linksBuilder.single(link("reviewMark", pullRequestResourceLinks.pullRequest().reviewMark(namespace, name, pullRequestId)));
    linksBuilder.single(link("sourceBranch", branchLinkProvider.get(repository.getNamespaceAndName(), pullRequest.getSource())));
    linksBuilder.single(link("targetBranch", branchLinkProvider.get(repository.getNamespaceAndName(), pullRequest.getTarget())));
    if (pullRequest.getStatus() == PullRequestStatus.OPEN) {
        linksBuilder.single(link("workflowResult", pullRequestResourceLinks.workflowEngineLinks().results(namespace, name, pullRequest.getId())));
    }
    Embedded.Builder embeddedBuilder = embeddedBuilder();
    applyEnrichers(new EdisonHalAppender(linksBuilder, embeddedBuilder), pullRequest, repository);
    return new PullRequestDto(linksBuilder.build(), embeddedBuilder.build());
}
Also used : EdisonHalAppender(sonia.scm.web.EdisonHalAppender) Links(de.otto.edison.hal.Links) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) Embedded(de.otto.edison.hal.Embedded) ObjectFactory(org.mapstruct.ObjectFactory)

Example 5 with ObjectFactory

use of org.mapstruct.ObjectFactory in project scm-review-plugin by scm-manager.

the class RepositoryEngineConfigMapper method create.

@ObjectFactory
RepositoryEngineConfigDto create(@Context Repository repository, @Context UriInfo uriInfo) {
    final Links.Builder linksBuilder = new Links.Builder();
    PullRequestResourceLinks links = new PullRequestResourceLinks(uriInfo::getBaseUri);
    PullRequestResourceLinks.WorkflowEngineConfigLinks workflowEngineConfigLinks = links.workflowEngineConfigLinks();
    linksBuilder.self(workflowEngineConfigLinks.getConfig(repository.getNamespace(), repository.getName()));
    if (!globalEngineConfigurator.getEngineConfiguration().isDisableRepositoryConfiguration()) {
        if (PermissionCheck.mayConfigureWorkflowConfig(repository)) {
            linksBuilder.single(link("update", workflowEngineConfigLinks.setConfig(repository.getNamespace(), repository.getName())));
        }
        if (PermissionCheck.mayReadWorkflowConfig(repository) || PermissionCheck.mayConfigureWorkflowConfig(repository)) {
            linksBuilder.single(link("availableRules", links.workflowEngineGlobalConfigLinks().availableRules()));
        }
    }
    return new RepositoryEngineConfigDto(linksBuilder.build());
}
Also used : Links(de.otto.edison.hal.Links) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) ObjectFactory(org.mapstruct.ObjectFactory)

Aggregations

Links (de.otto.edison.hal.Links)5 ObjectFactory (org.mapstruct.ObjectFactory)5 PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)3 LinkBuilder (sonia.scm.api.v2.resources.LinkBuilder)2 Embedded (de.otto.edison.hal.Embedded)1 EdisonHalAppender (sonia.scm.web.EdisonHalAppender)1