Search in sources :

Example 1 with Value

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);
}
Also used : ProjectTypeResolution(org.eclipse.che.api.project.server.type.ProjectTypeResolution) HashMap(java.util.HashMap) DefaultValue(javax.ws.rs.DefaultValue) Value(org.eclipse.che.api.core.model.project.type.Value) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with Value

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;
}
Also used : ProjectTypeResolution(org.eclipse.che.api.project.server.type.ProjectTypeResolution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) DefaultValue(javax.ws.rs.DefaultValue) Value(org.eclipse.che.api.core.model.project.type.Value) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Value

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);
}
Also used : Maps.newHashMap(com.google.common.collect.Maps.newHashMap) HashMap(java.util.HashMap) Attribute(org.eclipse.che.api.core.model.project.type.Attribute) Value(org.eclipse.che.api.core.model.project.type.Value) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)3 Map (java.util.Map)3 Value (org.eclipse.che.api.core.model.project.type.Value)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DefaultValue (javax.ws.rs.DefaultValue)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)2 ProjectTypeResolution (org.eclipse.che.api.project.server.type.ProjectTypeResolution)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Attribute (org.eclipse.che.api.core.model.project.type.Attribute)1 SourceEstimation (org.eclipse.che.api.project.shared.dto.SourceEstimation)1