use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class UserDaoTest method shouldNotRemoveUserWhenSubscriberThrowsExceptionOnUserRemoving.
@Test(dependsOnMethods = "shouldGetUserById")
public void shouldNotRemoveUserWhenSubscriberThrowsExceptionOnUserRemoving() throws Exception {
final UserImpl user = users[0];
CascadeEventSubscriber<BeforeUserRemovedEvent> subscriber = mockCascadeEventSubscriber();
doThrow(new ServerException("error")).when(subscriber).onCascadeEvent(any());
eventService.subscribe(subscriber, BeforeUserRemovedEvent.class);
try {
userDao.remove(user.getId());
fail("UserDao#remove had to throw server exception");
} catch (ServerException ignored) {
}
assertEqualsNoPassword(userDao.getById(user.getId()), user);
eventService.unsubscribe(subscriber, BeforeUserRemovedEvent.class);
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class ArchetypeGenerationStrategy method generateProject.
@Override
public void generateProject(final Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
AttributeValue artifactId = attributes.get(ARTIFACT_ID);
AttributeValue groupId = attributes.get(GROUP_ID);
AttributeValue version = attributes.get(VERSION);
if (groupId == null || artifactId == null || version == null) {
throw new ServerException("Missed some required attribute (groupId, artifactId or version)");
}
String archetypeGroupId = null;
String archetypeArtifactId = null;
String archetypeVersion = null;
String archetypeRepository = null;
Map<String, String> archetypeProperties = new HashMap<>();
//TODO: remove prop 'type' now it use only for detecting generation strategy
options.remove("type");
for (Entry<String, String> entry : options.entrySet()) {
switch(entry.getKey()) {
case "archetypeGroupId":
archetypeGroupId = entry.getValue();
break;
case "archetypeArtifactId":
archetypeArtifactId = entry.getValue();
break;
case "archetypeVersion":
archetypeVersion = entry.getValue();
break;
case "archetypeRepository":
archetypeRepository = entry.getValue();
break;
default:
archetypeProperties.put(entry.getKey(), entry.getValue());
}
}
if (isNullOrEmpty(archetypeGroupId) || isNullOrEmpty(archetypeArtifactId) || isNullOrEmpty(archetypeVersion)) {
throw new ServerException("Missed some required option (archetypeGroupId, archetypeArtifactId or archetypeVersion)");
}
MavenArchetype mavenArchetype = new MavenArchetypeImpl(archetypeGroupId, archetypeArtifactId, archetypeVersion, archetypeRepository, archetypeProperties);
final MavenArtifact mavenArtifact = new MavenArtifact();
mavenArtifact.setGroupId(getFirst(groupId.getList(), projectPath.getName()));
mavenArtifact.setArtifactId(getFirst(artifactId.getList(), projectPath.getName()));
mavenArtifact.setVersion(getFirst(version.getList(), DEFAULT_VERSION));
archetypeGenerator.generateFromArchetype(vfs.getRoot().toIoFile(), mavenArchetype, mavenArtifact);
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class MavenServerService method createProblem.
private Problem createProblem(VirtualFileEntry entry, SAXParseException spe) {
Problem problem = DtoFactory.newDto(Problem.class);
problem.setError(true);
problem.setMessage(spe.getMessage());
if (entry != null) {
int lineNumber = spe.getLineNumber();
int columnNumber = spe.getColumnNumber();
try {
String content = entry.getVirtualFile().getContentAsString();
Document document = new Document(content);
int lineOffset = document.getLineOffset(lineNumber - 1);
problem.setSourceStart(lineOffset + columnNumber - 1);
problem.setSourceEnd(lineOffset + columnNumber);
} catch (ForbiddenException | ServerException | BadLocationException e) {
LOG.error(e.getMessage(), e);
}
}
return problem;
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class MavenServerService method reconcilePom.
@GET
@Path("pom/reconcile")
@ApiOperation(value = "Reconcile pom.xml file")
@ApiResponses({ @ApiResponse(code = 200, message = "OK") })
@Produces("application/json")
public List<Problem> reconcilePom(@ApiParam(value = "The paths to pom.xml file which need to be reconciled") @QueryParam("pompath") String pomPath) {
VirtualFileEntry entry = null;
List<Problem> result = new ArrayList<>();
try {
entry = cheProjectManager.getProjectsRoot().getChild(pomPath);
if (entry == null) {
return result;
}
Model.readFrom(entry.getVirtualFile());
org.eclipse.che.api.vfs.Path path = entry.getPath();
String pomContent = entry.getVirtualFile().getContentAsString();
MavenProject mavenProject = mavenProjectManager.findMavenProject(ResourcesPlugin.getWorkspace().getRoot().getProject(path.getParent().toString()));
if (mavenProject == null) {
return result;
}
List<MavenProjectProblem> problems = mavenProject.getProblems();
int start = pomContent.indexOf("<project ") + 1;
int end = start + "<project ".length();
List<Problem> problemList = problems.stream().map(mavenProjectProblem -> DtoFactory.newDto(Problem.class).withError(true).withSourceStart(start).withSourceEnd(end).withMessage(mavenProjectProblem.getDescription())).collect(Collectors.toList());
result.addAll(problemList);
} catch (ServerException | ForbiddenException | IOException e) {
LOG.error(e.getMessage(), e);
} catch (XMLTreeException exception) {
Throwable cause = exception.getCause();
if (cause != null && cause instanceof SAXParseException) {
result.add(createProblem(entry, (SAXParseException) cause));
}
}
return result;
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class MavenServerService method reimportDependencies.
@POST
@Path("reimport")
@ApiOperation(value = "Re-import maven model")
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response reimportDependencies(@ApiParam(value = "The paths to projects which need to be reimported") @QueryParam("projectPath") List<String> paths) throws ServerException {
IWorkspace workspace = eclipseWorkspaceProvider.get();
List<IProject> projectsList = paths.stream().map(projectPath -> workspace.getRoot().getProject(projectPath)).collect(Collectors.toList());
mavenWorkspace.update(projectsList);
return Response.ok().build();
}
Aggregations