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);
}
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);
}
}
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();
}
Aggregations