use of org.eclipse.che.api.project.shared.dto.SourceEstimation in project che by eclipse.
the class ProjectServiceTest method testResolveSources.
@Test
public void testResolveSources() throws Exception {
VirtualFile root = pm.getProjectsRoot().getVirtualFile();
root.createFolder("testEstimateProjectGood").createFolder("check");
root.createFolder("testEstimateProjectBad");
final ValueProviderFactory vpf1 = projectFolder -> new ReadonlyValueProvider() {
@Override
public List<String> getValues(String attributeName) throws ValueStorageException {
VirtualFileEntry file;
try {
file = projectFolder.getChild("check");
} catch (ServerException e) {
throw new ValueStorageException(e.getMessage());
}
if (file == null) {
throw new ValueStorageException("Check not found");
}
return (List<String>) singletonList("checked");
}
};
ProjectTypeDef pt = new ProjectTypeDef("testEstimateProjectPT", "my testEstimateProject type", true, false) {
{
addVariableDefinition("calculated_attribute", "attr description", true, vpf1);
addVariableDefinition("my_property_1", "attr description", true);
addVariableDefinition("my_property_2", "attr description", false);
}
};
ptRegistry.registerProjectType(pt);
ContainerResponse response = launcher.service(GET, format("http://localhost:8080/api/project/resolve/%s", "testEstimateProjectGood"), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
List<SourceEstimation> result = (List<SourceEstimation>) response.getEntity();
assertTrue(result.size() > 0);
boolean m = false;
for (SourceEstimation est : result) {
if (est.getType().equals("testEstimateProjectPT")) {
assertTrue(est.isMatched());
m = true;
}
}
assertTrue(m);
}
use of org.eclipse.che.api.project.shared.dto.SourceEstimation in project che by eclipse.
the class ProjectResolver method resolve.
public Promise<Project> resolve(final Project project) {
return project.resolve().thenPromise(new Function<List<SourceEstimation>, Promise<Project>>() {
@Override
public Promise<Project> apply(List<SourceEstimation> estimations) throws FunctionException {
if (estimations == null || estimations.isEmpty()) {
return promiseProvider.resolve(project);
}
final List<String> primeTypes = newArrayList();
for (SourceEstimation estimation : estimations) {
if (projectTypeRegistry.getProjectType(estimation.getType()).isPrimaryable()) {
primeTypes.add(estimation.getType());
}
}
final MutableProjectConfig config = new MutableProjectConfig(project);
final SourceStorage source = project.getSource();
if (source != null && source.getParameters() != null && source.getParameters().containsKey("keepDir")) {
config.setType(Constants.BLANK_ID);
} else if (primeTypes.isEmpty()) {
return promiseProvider.resolve(project);
} else if (primeTypes.size() == 1) {
config.setType(primeTypes.get(0));
} else {
config.setType(Constants.BLANK_ID);
projectWizard.show(config);
return promiseProvider.resolve(project);
}
return project.update().withBody(config).send();
}
}).catchErrorPromise(new Function<PromiseError, Promise<Project>>() {
@Override
public Promise<Project> apply(PromiseError error) throws FunctionException {
Log.warn(ProjectResolver.class, error.getMessage());
return promiseProvider.resolve(project);
}
});
}
use of org.eclipse.che.api.project.shared.dto.SourceEstimation in project che by eclipse.
the class MavenPagePresenterTest method warningWindowShouldBeShowedIfProjectEstimationHasSomeError.
@Test
public void warningWindowShouldBeShowedIfProjectEstimationHasSomeError() throws Exception {
final String dialogTitle = "Not valid Maven project";
PromiseError promiseError = mock(PromiseError.class);
MessageDialog messageDialog = mock(MessageDialog.class);
context.put(WIZARD_MODE_KEY, UPDATE.toString());
when(promiseError.getMessage()).thenReturn(TEXT);
when(localization.mavenPageErrorDialogTitle()).thenReturn(dialogTitle);
when(dialogFactory.createMessageDialog(anyString(), anyString(), anyObject())).thenReturn(messageDialog);
when(sourceEstimationPromise.then(Matchers.<Operation<SourceEstimation>>anyObject())).thenReturn(sourceEstimationPromise);
when(sourceEstimationPromise.catchError(Matchers.<Operation<PromiseError>>anyObject())).thenReturn(sourceEstimationPromise);
mavenPagePresenter.init(projectConfig);
verify(containerPromise).then(optionContainerCapture.capture());
optionContainerCapture.getValue().apply(optionalContainer);
verify(sourceEstimationPromise).catchError(containerArgumentErrorCapture.capture());
containerArgumentErrorCapture.getValue().apply(promiseError);
verify(promiseError).getMessage();
verify(dialogFactory).createMessageDialog(dialogTitle, TEXT, null);
verify(messageDialog).show();
}
use of org.eclipse.che.api.project.shared.dto.SourceEstimation in project che by eclipse.
the class ProjectServiceTest method testEstimateProject.
@Test
public void testEstimateProject() throws Exception {
VirtualFile root = pm.getProjectsRoot().getVirtualFile();
//getVirtualFileSystemRegistry().getProvider("my_ws").getMountPoint(false).getRoot();
root.createFolder("testEstimateProjectGood").createFolder("check");
root.createFolder("testEstimateProjectBad");
String errMessage = "File /check not found";
final ValueProviderFactory vpf1 = projectFolder -> new ReadonlyValueProvider() {
@Override
public List<String> getValues(String attributeName) throws ValueStorageException {
VirtualFileEntry file;
try {
file = projectFolder.getChild("check");
} catch (ServerException e) {
throw new ValueStorageException(e.getMessage());
}
if (file == null) {
throw new ValueStorageException(errMessage);
}
return (List<String>) singletonList("checked");
}
};
ProjectTypeDef pt = new ProjectTypeDef("testEstimateProjectPT", "my testEstimateProject type", true, false) {
{
addVariableDefinition("calculated_attribute", "attr description", true, vpf1);
addVariableDefinition("my_property_1", "attr description", true);
addVariableDefinition("my_property_2", "attr description", false);
}
};
ptRegistry.registerProjectType(pt);
ContainerResponse response = launcher.service(GET, format("http://localhost:8080/api/project/estimate/%s?type=%s", "testEstimateProjectGood", "testEstimateProjectPT"), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
//noinspection unchecked
SourceEstimation result = (SourceEstimation) response.getEntity();
assertTrue(result.isMatched());
assertEquals(result.getAttributes().size(), 1);
assertEquals(result.getAttributes().get("calculated_attribute").get(0), "checked");
// if project not matched
response = launcher.service(GET, format("http://localhost:8080/api/project/estimate/%s?type=%s", "testEstimateProjectBad", "testEstimateProjectPT"), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
//noinspection unchecked
result = (SourceEstimation) response.getEntity();
assertFalse(result.isMatched());
assertEquals(result.getAttributes().size(), 0);
}
use of org.eclipse.che.api.project.shared.dto.SourceEstimation in project che by eclipse.
the class ProjectService method resolveSources.
@GET
@Path("/resolve/{path:.*}")
@Produces(MediaType.APPLICATION_JSON)
public List<SourceEstimation> resolveSources(@ApiParam(value = "Path to requested project", required = true) @PathParam("path") String path) throws NotFoundException, ForbiddenException, ServerException, ConflictException {
List<SourceEstimation> estimations = new ArrayList<>();
for (ProjectTypeResolution resolution : projectManager.resolveSources(path, false)) {
if (resolution.matched()) {
final HashMap<String, List<String>> attributes = new HashMap<>();
for (Map.Entry<String, Value> attr : resolution.getProvidedAttributes().entrySet()) {
attributes.put(attr.getKey(), attr.getValue().getList());
}
estimations.add(DtoFactory.newDto(SourceEstimation.class).withType(resolution.getType()).withMatched(resolution.matched()).withAttributes(attributes));
}
}
return estimations;
}
Aggregations