Search in sources :

Example 11 with ModelId

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

the class ModelRepositoryTest method testGetModelWithNoImage.

@Test
public void testGetModelWithNoImage() {
    checkinModel("Color.type");
    checkinModel("Colorlight.fbmodel");
    checkinModel("Switcher.fbmodel");
    checkinModel("HueLightStrips.infomodel");
    assertEquals(false, this.modelRepository.getById(new ModelId("HueLightStrips", "com.mycompany", "1.0.0")).isHasImage());
}
Also used : ModelId(org.eclipse.vorto.repository.api.ModelId) Test(org.junit.Test) AbstractIntegrationTest(org.eclipse.vorto.repository.AbstractIntegrationTest)

Example 12 with ModelId

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

the class Lwm2mObjectIdResolverTest method testResolveForExistingObjectId.

@Test
public void testResolveForExistingObjectId() {
    checkinModel("lwm2m/ColorLight.fbmodel");
    checkinModel("lwm2m/ColorLight_lwm2m.mapping");
    DefaultResolver lwm2mResolver = new DefaultResolver();
    lwm2mResolver.setRepository(this.modelRepository);
    assertEquals(new ModelId("ColorLight", "com.mycompany.fb", "1.0.0"), lwm2mResolver.resolve(new LWM2MQuery("2")));
    assertNotNull(this.modelRepository.getById(lwm2mResolver.resolve(new LWM2MQuery("2"))));
}
Also used : DefaultResolver(org.eclipse.vorto.repository.core.impl.resolver.DefaultResolver) LWM2MQuery(org.eclipse.vorto.repository.api.resolver.LWM2MQuery) ModelId(org.eclipse.vorto.repository.api.ModelId) AbstractIntegrationTest(org.eclipse.vorto.repository.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with ModelId

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

the class MappingSpecificationBuilder method build.

public IMappingSpecification build() {
    try {
        Infomodel infomodel = this.repositoryClient.getContent(ModelId.fromPrettyFormat(this.modelId), Infomodel.class, this.targetPlatformKey).get();
        DefaultMappingSpecification specification = new DefaultMappingSpecification();
        specification.setInfomodel(infomodel);
        for (ModelProperty fbProperty : infomodel.getFunctionblocks()) {
            ModelId fbModelId = (ModelId) fbProperty.getType();
            ModelId mappingId = fbProperty.getMappingReference();
            FunctionblockModel fbm;
            if (mappingId != null) {
                fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, mappingId).get();
            } else {
                fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, this.targetPlatformKey).get();
            }
            if (fbm.getStereotype(STEREOTYPE_FUNCTIONS).isPresent()) {
                Stereotype functionsStereotype = fbm.getStereotype(STEREOTYPE_FUNCTIONS).get();
                JavascriptFunctions functions = new JavascriptFunctions(fbProperty.getName().toLowerCase());
                for (String functionName : functionsStereotype.getAttributes().keySet()) {
                    if (!"_namespace".equalsIgnoreCase(functionName)) {
                        functions.addFunction(functionName, functionsStereotype.getAttributes().get(functionName));
                    }
                }
                this.library.addFunctions(functions);
            }
            specification.getFbs().put(fbProperty.getName(), fbm);
        }
        specification.setLibrary(this.library);
        return specification;
    } catch (Exception e) {
        throw new MappingSpecificationProblem("Problem reading mapping specification", e);
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) DefaultMappingSpecification(org.eclipse.vorto.service.mapping.internal.spec.DefaultMappingSpecification) JavascriptFunctions(org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Stereotype(org.eclipse.vorto.repository.api.content.Stereotype) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 14 with ModelId

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

the class JcrModelRepository method getMappingModelsForTargetPlatform.

@Override
public List<ModelInfo> getMappingModelsForTargetPlatform(ModelId modelId, String targetPlatform) {
    List<ModelInfo> mappingResources = new ArrayList<>();
    ModelInfo modelResource = getById(modelId);
    if (modelResource != null) {
        for (ModelId referenceeModelId : modelResource.getReferencedBy()) {
            ModelInfo referenceeModelResources = getById(referenceeModelId);
            if (referenceeModelResources.getType() == ModelType.Mapping && isTargetPlatformMapping(referenceeModelResources, targetPlatform)) {
                mappingResources.add(referenceeModelResources);
            }
        }
        for (ModelId referencedModelId : modelResource.getReferences()) {
            mappingResources.addAll(getMappingModelsForTargetPlatform(referencedModelId, targetPlatform));
        }
    }
    return mappingResources;
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ArrayList(java.util.ArrayList) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 15 with ModelId

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

the class ModelSequencer method execute.

@Override
public boolean execute(Property inputProperty, Node outputNode, Context context) throws Exception {
    Binary binaryValue = inputProperty.getBinary();
    CheckArg.isNotNull(binaryValue, "binary");
    ModelInfo modelResource = ModelParserFactory.getParser(outputNode.getPath()).parse(binaryValue.getStream());
    outputNode.setProperty("vorto:description", modelResource.getDescription() != null ? modelResource.getDescription() : "");
    outputNode.setProperty("vorto:type", modelResource.getType().name());
    outputNode.setProperty("vorto:displayname", modelResource.getDisplayName());
    outputNode.setProperty("vorto:version", modelResource.getId().getVersion());
    outputNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
    outputNode.setProperty("vorto:name", modelResource.getId().getName());
    ModelReferencesHelper referencesHelper = new ModelReferencesHelper(modelResource.getReferences());
    if (referencesHelper.hasReferences()) {
        List<Value> references = new ArrayList<Value>();
        for (ModelId modelId : referencesHelper.getReferences()) {
            ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
            Node referencedFolder = outputNode.getSession().getNode(modelIdHelper.getFullPath());
            Node reference = referencedFolder.getNodes().nextNode();
            references.add(context.valueFactory().createValue(reference));
        }
        outputNode.setProperty("vorto:references", references.toArray(new Value[references.size()]));
    }
    return true;
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) ModelReferencesHelper(org.eclipse.vorto.repository.core.impl.utils.ModelReferencesHelper) Node(javax.jcr.Node) Value(javax.jcr.Value) ArrayList(java.util.ArrayList) Binary(javax.jcr.Binary) ModelId(org.eclipse.vorto.repository.api.ModelId)

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