use of org.eclipse.che.api.core.model.project.type.Value in project che by eclipse.
the class ProjectService method estimateProject.
@GET
@Path("/estimate/{path:.*}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Estimates if the folder supposed to be project of certain type", response = Map.class)
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Project with specified path doesn't exist in workspace"), @ApiResponse(code = 403, message = "Access to requested project is forbidden"), @ApiResponse(code = 500, message = "Server error") })
public SourceEstimation estimateProject(@ApiParam(value = "Path to requested project", required = true) @PathParam("path") String path, @ApiParam(value = "Project Type ID to estimate against", required = true) @QueryParam("type") String projectType) throws NotFoundException, ForbiddenException, ServerException, ConflictException {
final ProjectTypeResolution resolution = projectManager.estimateProject(path, projectType);
final HashMap<String, List<String>> attributes = new HashMap<>();
for (Map.Entry<String, Value> attr : resolution.getProvidedAttributes().entrySet()) {
attributes.put(attr.getKey(), attr.getValue().getList());
}
return DtoFactory.newDto(SourceEstimation.class).withType(projectType).withMatched(resolution.matched()).withResolution(resolution.getResolution()).withAttributes(attributes);
}
use of org.eclipse.che.api.core.model.project.type.Value 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;
}
use of org.eclipse.che.api.core.model.project.type.Value in project che by eclipse.
the class ProjectTypeDef method resolveSources.
public ProjectTypeResolution resolveSources(FolderEntry projectFolder) {
Map<String, Value> matchAttrs = new HashMap<>();
for (Map.Entry<String, Attribute> entry : attributes.entrySet()) {
Attribute attr = entry.getValue();
String name = entry.getKey();
if (attr.isVariable()) {
Variable var = (Variable) attr;
ValueProviderFactory factory = var.getValueProviderFactory();
if (factory != null) {
Value value;
String errorMessage = "";
try {
value = new AttributeValue(factory.newInstance(projectFolder).getValues(name));
} catch (ValueStorageException e) {
value = null;
errorMessage = e.getLocalizedMessage();
}
if (value == null || value.isEmpty()) {
if (var.isRequired()) {
// this PT is not match
errorMessage = errorMessage.isEmpty() ? format("Value for required attribute %s is not initialized", name) : errorMessage;
return new DefaultResolution(id, errorMessage);
}
} else {
// add one more matched attribute
matchAttrs.put(name, value);
}
}
}
}
return new DefaultResolution(id, matchAttrs, true);
}
Aggregations