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));
}
}
}
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");
}
}
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");
}
}
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);
}
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");
}
}
Aggregations