Search in sources :

Example 71 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class MappingSpecificationSerializer method addSerializerRecursive.

private void addSerializerRecursive(ModelId parentId, IModel container, List<ModelProperty> properties, List<IMappingSerializer> serializers) {
    for (ModelProperty property : properties) {
        if (isEntityProperty(property)) {
            EntityModel entityModel = (EntityModel) property.getType();
            ModelId mappingId = MappingIdUtils.getIdForProperty(parentId, property);
            addSerializerRecursive(mappingId, entityModel, entityModel.getProperties(), serializers);
            serializers.add(new EntityMappingSerializer(specification, mappingId, targetPlatform, property.getName(), entityModel));
        }
    }
}
Also used : ModelProperty(org.eclipse.vorto.model.ModelProperty) EntityModel(org.eclipse.vorto.model.EntityModel) ModelId(org.eclipse.vorto.model.ModelId)

Example 72 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryAttachmentTest method testExtractAttachedFileContent.

@Test
public void testExtractAttachedFileContent() throws Exception {
    IUserContext erle = createUserContext("erle", "playground");
    ModelInfo model = importModel("Color.type", erle);
    attachFile(model);
    try {
        Optional<FileContent> colorXmi = repositoryFactory.getRepository(erle).getAttachmentContent(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), "Color.xmi");
        assertFalse(colorXmi.isPresent());
        Optional<FileContent> backup1 = repositoryFactory.getRepository(erle).getAttachmentContent(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), "backup1.xml");
        assertTrue(backup1.isPresent());
        byte[] backup1Array = IOUtils.toByteArray(new ClassPathResource("sample_models/backup1.xml").getInputStream());
        assertTrue(Arrays.equals(backup1Array, backup1.get().getContent()));
    } catch (IOException | FatalModelRepositoryException e) {
        e.printStackTrace();
        fail("Cannot load sample file");
    }
}
Also used : IOException(java.io.IOException) ModelId(org.eclipse.vorto.model.ModelId) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 73 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryAttachmentTest method testAttachFileWithMultipleTags.

@Test
public void testAttachFileWithMultipleTags() {
    IUserContext erle = createUserContext("erle", "playground");
    importModel("Color.type", erle);
    try {
        repositoryFactory.getRepository(erle).attachFile(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), new FileContent("backup1.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup1.xml").getInputStream())), erle, Attachment.TAG_DOCUMENTATION, Attachment.TAG_IMAGE);
        List<Attachment> attachments = repositoryFactory.getRepository(erle).getAttachmentsByTag(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), Attachment.TAG_IMAGE);
        assertEquals(2, attachments.get(0).getTags().size());
        attachments.forEach(name -> System.out.println(name));
    } catch (IOException | FatalModelRepositoryException e) {
        e.printStackTrace();
        fail("Cannot load sample file");
    }
}
Also used : IOException(java.io.IOException) ModelId(org.eclipse.vorto.model.ModelId) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 74 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryAttachmentTest method testDeleteOfAttachmentTwice.

@Test
public void testDeleteOfAttachmentTwice() throws Exception {
    IUserContext erle = createUserContext("erle", "playground");
    importModel("Color.type", erle);
    ModelId modelId = new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0");
    repositoryFactory.getRepository(erle).attachFile(modelId, new FileContent("backup1.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup1.xml").getInputStream())), erle);
    repositoryFactory.getRepository(erle).deleteAttachment(modelId, "backup1.xml");
    boolean deleteResult1 = repositoryFactory.getRepository(erle).deleteAttachment(modelId, "backup1.xml");
    assertFalse(deleteResult1);
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 75 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryAttachmentTest method testAttachFileWithMultipleCustomTags.

@Test
public void testAttachFileWithMultipleCustomTags() {
    IUserContext erle = createUserContext("erle", "playground");
    importModel("Color.type", erle);
    Tag myCustomTag1 = new Tag("myCustom");
    Tag myCustomTag2 = new Tag("myCustom2");
    try {
        repositoryFactory.getRepository(erle).attachFile(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), new FileContent("backup1.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup1.xml").getInputStream())), erle, myCustomTag1, myCustomTag2);
        List<Attachment> attachments = repositoryFactory.getRepository(erle).getAttachments(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"));
        assertEquals(1, attachments.size());
        assertEquals(2, attachments.get(0).getTags().size());
        assertEquals(1, attachments.stream().map(Attachment::getTags).flatMap(Collection::stream).filter(myCustomTag1::equals).count());
        assertEquals(1, attachments.stream().map(Attachment::getTags).flatMap(Collection::stream).filter(myCustomTag2::equals).count());
        attachments.forEach(System.out::println);
    } catch (IOException | FatalModelRepositoryException e) {
        e.printStackTrace();
        fail("Cannot load sample file");
    }
}
Also used : IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Aggregations

ModelId (org.eclipse.vorto.model.ModelId)124 Test (org.junit.Test)48 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)29 IOException (java.io.IOException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)19 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ResponseEntity (org.springframework.http.ResponseEntity)14 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)13 ModelType (org.eclipse.vorto.model.ModelType)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)12 Autowired (org.springframework.beans.factory.annotation.Autowired)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 Optional (java.util.Optional)10 List (java.util.List)9 IOUtils (org.apache.commons.io.IOUtils)9 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)9 ModelLink (org.eclipse.vorto.repository.web.api.v1.dto.ModelLink)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ApiOperation (io.swagger.annotations.ApiOperation)8