Search in sources :

Example 16 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class AbstractModelParser method parseModelIdFromFileName.

private ModelId parseModelIdFromFileName() {
    String pureFileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.lastIndexOf("."));
    ModelId modelId = new ModelId();
    try {
        modelId.setNamespace(pureFileName.substring(0, pureFileName.lastIndexOf(".")));
        modelId.setName(pureFileName.substring(pureFileName.lastIndexOf(".") + 1, pureFileName.indexOf("_")));
        String version = pureFileName.substring(pureFileName.indexOf("_") + 1);
        version = version.replaceAll("_", ".");
        modelId.setVersion(version.substring(0, 5));
    } catch (Throwable t) {
        return new ModelId(pureFileName, "", "0.0.0");
    }
    return modelId;
}
Also used : ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 17 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class DataValidation method main.

public static void main(String[] args) {
    ModelId presenceCapability = ModelId.fromPrettyFormat("com.ipso.smartobjects.Presence:0.0.1");
    JSONObject jsonSchema = getSchemaForCapability(presenceCapability);
    JSONObject jsonInput = getJsonInput();
    Schema schema = SchemaLoader.load(jsonSchema);
    try {
        schema.validate(jsonInput);
        System.out.println("Congrats. The JSON is valid");
    } catch (ValidationException validationException) {
        System.err.println("JSON is not valid according to schema");
        validationException.printStackTrace();
    }
}
Also used : ValidationException(org.everit.json.schema.ValidationException) JSONObject(org.json.JSONObject) Schema(org.everit.json.schema.Schema) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 18 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class DefaultModelPublisher method publish.

@Override
public ModelId publish(ModelType type, String content) throws ModelPublishException {
    String uploadModelsUrl = String.format("%s/rest/secure", getRequestContext().getBaseUrl());
    HttpPost query = new HttpPost(uploadModelsUrl);
    HttpEntity entity = MultipartEntityBuilder.create().addPart("fileName", new StringBody("vortomodel" + type.getExtension(), ContentType.DEFAULT_TEXT)).addPart("fileDescription", new StringBody("", ContentType.DEFAULT_TEXT)).addPart("file", new ByteArrayBody(content.getBytes(), ContentType.APPLICATION_OCTET_STREAM, "vortomodel" + type.getExtension())).build();
    query.setEntity(entity);
    try {
        CompletableFuture<UploadModelResponse> response = execute(query, new TypeToken<UploadModelResponse>() {
        }.getType());
        List<UploadModelResult> result = response.get().getObj();
        if (response.get().getIsSuccess()) {
            String checkinModelUrl = String.format("%s/rest/secure/%s", getRequestContext().getBaseUrl(), result.get(0).getHandleId());
            HttpPut checkInModel = new HttpPut(checkinModelUrl);
            CompletableFuture<ModelId> checkedInResult = execute(checkInModel, new TypeToken<ModelId>() {
            }.getType());
            return (ModelId) checkedInResult.get();
        } else {
            throw new ModelPublishException(result.get(0));
        }
    } catch (Throwable ex) {
        if (!(ex instanceof ModelPublishException)) {
            throw new RuntimeException(ex);
        } else {
            throw ((ModelPublishException) ex);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) UploadModelResult(org.eclipse.vorto.repository.api.upload.UploadModelResult) HttpEntity(org.apache.http.HttpEntity) ModelPublishException(org.eclipse.vorto.repository.api.upload.ModelPublishException) ByteArrayBody(org.apache.http.entity.mime.content.ByteArrayBody) UploadModelResponse(org.eclipse.vorto.repository.api.upload.UploadModelResponse) HttpPut(org.apache.http.client.methods.HttpPut) StringBody(org.apache.http.entity.mime.content.StringBody) TypeToken(com.google.gson.reflect.TypeToken) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 19 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class JcrModelRepository method createModelResource.

private ModelInfo createModelResource(Node node) throws RepositoryException {
    ModelInfo resource = createMinimalModelInfo(node);
    if (node.hasProperty("vorto:references")) {
        Value[] referenceValues = null;
        try {
            referenceValues = node.getProperty("vorto:references").getValues();
        } catch (Exception ex) {
            referenceValues = new Value[] { node.getProperty("vorto:references").getValue() };
        }
        if (referenceValues != null) {
            ModelReferencesHelper referenceHelper = new ModelReferencesHelper();
            for (Value referValue : referenceValues) {
                String nodeUuid = referValue.getString();
                Node referencedNode = session.getNodeByIdentifier(nodeUuid);
                referenceHelper.addModelReference(ModelIdHelper.fromPath(referencedNode.getParent().getPath()).getPrettyFormat());
            }
            resource.setReferences(referenceHelper.getReferences());
        }
    }
    PropertyIterator propIter = node.getReferences();
    while (propIter.hasNext()) {
        Property prop = propIter.nextProperty();
        Node referencedByFileNode = prop.getParent();
        final ModelId referencedById = ModelIdHelper.fromPath(referencedByFileNode.getParent().getPath());
        resource.getReferencedBy().add(referencedById);
        if (referencedByFileNode.getName().endsWith(ModelType.Mapping.getExtension())) {
            ModelEMFResource emfResource = getEMFResource(referencedById);
            resource.addPlatformMapping(emfResource.getTargetPlatform(), referencedById);
        }
    }
    return resource;
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ModelReferencesHelper(org.eclipse.vorto.repository.core.impl.utils.ModelReferencesHelper) Node(javax.jcr.Node) Value(javax.jcr.Value) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) ModelReferentialIntegrityException(org.eclipse.vorto.repository.core.ModelReferentialIntegrityException) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 20 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class DefaultResolver method doResolve.

@Override
protected ModelId doResolve(ModelInfo mappingModelResource, ResolveQuery query) {
    IModelContent content = this.repository.getModelContent(mappingModelResource.getId(), ContentType.DSL);
    MappingModel mappingModel = (MappingModel) content.getModel();
    Optional<MappingRule> objectRule = mappingModel.getRules().stream().filter(rule -> rule.getTarget() instanceof StereoTypeTarget && ((StereoTypeTarget) rule.getTarget()).getName().equals(query.getStereoType())).findFirst();
    if (objectRule.isPresent()) {
        Optional<Attribute> objectIdAttribute = ((StereoTypeTarget) objectRule.get().getTarget()).getAttributes().stream().filter(attribute -> attribute.getName().equals(query.getAttributeId())).findFirst();
        if (objectIdAttribute.isPresent() && objectIdAttribute.get().getValue().equals(query.getAttributeValue())) {
            return ModelId.fromReference(mappingModel.getReferences().get(0).getImportedNamespace(), mappingModel.getReferences().get(0).getVersion());
        }
    }
    return null;
}
Also used : IModelContent(org.eclipse.vorto.repository.core.IModelContent) Service(org.springframework.stereotype.Service) ContentType(org.eclipse.vorto.repository.core.IModelRepository.ContentType) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Optional(java.util.Optional) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ResolveQuery(org.eclipse.vorto.repository.api.resolver.ResolveQuery) ModelId(org.eclipse.vorto.repository.api.ModelId) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) IModelContent(org.eclipse.vorto.repository.core.IModelContent) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Aggregations

ModelId (org.eclipse.vorto.repository.api.ModelId)36 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 ApiOperation (io.swagger.annotations.ApiOperation)10 IOException (java.io.IOException)10 ApiResponses (io.swagger.annotations.ApiResponses)9 Test (org.junit.Test)9 ModelNotFoundException (org.eclipse.vorto.repository.api.exception.ModelNotFoundException)8 AbstractIntegrationTest (org.eclipse.vorto.repository.AbstractIntegrationTest)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)6 ContentType (org.eclipse.vorto.repository.core.IModelRepository.ContentType)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 UploadTooLargeException (org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Optional (java.util.Optional)4 ZipEntry (java.util.zip.ZipEntry)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)4 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)4