Search in sources :

Example 1 with ForkStatus

use of de.catma.project.ForkStatus in project catma by forTEXT.

the class ForkHandler method fork.

public void fork() {
    BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) ui;
    BackgroundService backgroundService = backgroundServiceProvider.accuireBackgroundService();
    backgroundService.submit(new DefaultProgressCallable<Void>() {

        @Override
        public Void call() throws Exception {
            final AtomicBoolean cancel = new AtomicBoolean(false);
            for (TagsetDefinition tagset : tagsets) {
                getProgressListener().setProgress("Forking Tagset %1$s into Project %2$s", tagset.getName(), targetProject.getName());
                ui.accessSynchronously(() -> {
                    try {
                        ForkStatus forkStatus = projectManager.forkTagset(tagset, projectId, targetProject);
                        if (forkStatus.isResourceAlreadyExists()) {
                            Notification.show("Info", String.format("The Tagset %1$s is already present in the target Project and cannot be forked!", tagset.getName()), Type.ERROR_MESSAGE);
                        } else if (forkStatus.isTargetHasConflicts()) {
                            Notification.show("Info", String.format("The target Project %1$s has conflicts, please open the Project and resolve the conflicts first!", targetProject.getName()), Type.ERROR_MESSAGE);
                            cancel.set(true);
                        } else if (forkStatus.isTargetNotClean()) {
                            Notification.show("Info", String.format("The target Project %1$s has uncommited changes, please open the Project and commit all changes first!", targetProject.getName()), Type.ERROR_MESSAGE);
                            cancel.set(true);
                        }
                    } catch (Exception e) {
                        ((ErrorHandler) UI.getCurrent()).showAndLogError("Error forking Tagsets", e);
                        cancel.set(true);
                    }
                });
                if (cancel.get()) {
                    return null;
                }
            }
            return null;
        }
    }, executionListener, progressListener);
}
Also used : ForkStatus(de.catma.project.ForkStatus) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TagsetDefinition(de.catma.tag.TagsetDefinition) ErrorHandler(de.catma.ui.module.main.ErrorHandler) BackgroundService(de.catma.backgroundservice.BackgroundService) BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider)

Example 2 with ForkStatus

use of de.catma.project.ForkStatus in project catma by forTEXT.

the class GitlabManagerRestricted method forkResource.

@Override
public ForkStatus forkResource(String resourceId, String sourceProjectId, String targetProjectId) throws IOException {
    try {
        Project sourceResourceProject = restrictedGitLabApi.getProjectApi().getProject(sourceProjectId, resourceId);
        Optional<Project> optionalTargetResource = restrictedGitLabApi.getProjectApi().getOptionalProject(targetProjectId, resourceId);
        if (optionalTargetResource.isPresent()) {
            return ForkStatus.resourceAlreadyExists();
        }
        restrictedGitLabApi.getProjectApi().forkProject(sourceResourceProject, targetProjectId);
        Project targetProject = restrictedGitLabApi.getProjectApi().getProject(targetProjectId, resourceId);
        Status importStatus = targetProject.getImportStatus();
        int tries = 10;
        while (importStatus != Status.FINISHED && tries > 0) {
            tries--;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                break;
            }
            logger.info(String.format("Trying to retrieve forked resource status for %1$s from group %2$s (try %3$d)", resourceId, targetProjectId, 10 - tries));
            importStatus = targetProject.getImportStatus();
        }
        if (importStatus != Status.FINISHED) {
            logger.warning(String.format("Status is still '%1$s' and not 'finished'! Trying to continue anyway!", importStatus));
        }
        return ForkStatus.success();
    } catch (GitLabApiException e) {
        throw new IOException(String.format("Failed to fork resource %1$s from group %2$s into group %3$s", resourceId, sourceProjectId, targetProjectId), e);
    }
}
Also used : Status(org.gitlab4j.api.models.ImportStatus.Status) ForkStatus(de.catma.project.ForkStatus) Project(org.gitlab4j.api.models.Project) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 3 with ForkStatus

use of de.catma.project.ForkStatus in project catma by forTEXT.

the class GitProjectManager method forkTagset.

@Override
public ForkStatus forkTagset(TagsetDefinition tagset, String sourceProjectId, ProjectReference targetProject) throws Exception {
    String targetProjectId = targetProject.getProjectId();
    String tagsetId = tagset.getUuid();
    cloneRootLocallyIfNotExists(targetProject, new OpenProjectListener() {

        @Override
        public void ready(Project project) {
        /**
         * not used *
         */
        }

        @Override
        public void conflictResolutionNeeded(ConflictedProject project) {
        /**
         * not used *
         */
        }

        @Override
        public void failure(Throwable t) {
        /**
         * not used *
         */
        }

        @Override
        public void progress(String msg, Object... params) {
            logger.info(String.format(msg, params));
        }
    });
    GitProjectHandler targetProjectHandler = new GitProjectHandler(this.user, targetProjectId, this.localGitRepositoryManager, this.remoteGitServerManager);
    targetProjectHandler.loadRolesPerResource();
    if (targetProjectHandler.hasConflicts()) {
        return ForkStatus.targetHasConflicts();
    } else if (targetProjectHandler.hasUncommittedChanges()) {
        return ForkStatus.targetNotClean();
    }
    ForkStatus forkStatus = remoteGitServerManager.forkResource(tagsetId, sourceProjectId, targetProjectId);
    if (forkStatus.isSuccess()) {
        targetProjectHandler.cloneAndAddTagset(tagset.getUuid(), tagset.getName(), String.format("Forked Tagset %1$s with ID %2$s from %3$s with ID %4$s", tagset.getName(), tagset.getUuid(), targetProject.getName(), targetProjectId));
    } else {
        return forkStatus;
    }
    return ForkStatus.success();
}
Also used : ForkStatus(de.catma.project.ForkStatus) Project(de.catma.project.Project) ConflictedProject(de.catma.project.conflict.ConflictedProject) OpenProjectListener(de.catma.project.OpenProjectListener) JsonObject(com.google.gson.JsonObject) ConflictedProject(de.catma.project.conflict.ConflictedProject)

Aggregations

ForkStatus (de.catma.project.ForkStatus)3 JsonObject (com.google.gson.JsonObject)1 BackgroundService (de.catma.backgroundservice.BackgroundService)1 BackgroundServiceProvider (de.catma.backgroundservice.BackgroundServiceProvider)1 OpenProjectListener (de.catma.project.OpenProjectListener)1 Project (de.catma.project.Project)1 ConflictedProject (de.catma.project.conflict.ConflictedProject)1 TagsetDefinition (de.catma.tag.TagsetDefinition)1 ErrorHandler (de.catma.ui.module.main.ErrorHandler)1 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 GitLabApiException (org.gitlab4j.api.GitLabApiException)1 Status (org.gitlab4j.api.models.ImportStatus.Status)1 Project (org.gitlab4j.api.models.Project)1