Search in sources :

Example 56 with ModelId

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

the class IndexingEventListener method onApplicationEvent.

@Override
public void onApplicationEvent(AppEvent event) {
    if (event.getEventType() == EventType.MODEL_CREATED) {
        ModelInfo modelInfo = (ModelInfo) event.getSubject();
        indexingService.indexModel(modelInfo, event.getUserContext().getWorkspaceId());
    } else if (event.getEventType() == EventType.MODEL_UPDATED) {
        ModelInfo modelInfo = (ModelInfo) event.getSubject();
        indexingService.updateIndex(modelInfo);
    } else if (event.getEventType() == EventType.MODEL_DELETED) {
        ModelId modelId = (ModelId) event.getSubject();
        indexingService.deleteIndex(modelId);
    } else if (event.getEventType() == EventType.NAMESPACE_DELETED) {
        indexingService.deleteIndexForWorkspace(event.getUserContext().getWorkspaceId());
    }
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelId(org.eclipse.vorto.model.ModelId)

Example 57 with ModelId

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

the class IntegrationTestBase method addLink.

protected ResultActions addLink(String modelId, SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor user, ModelLink url) throws Exception {
    MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.put("/api/v1/attachments/" + modelId + "/links");
    builder.content(ObjectMapperFactory.getInstance().writeValueAsString(url));
    return repositoryServer.perform(builder.with(request -> {
        request.setMethod("PUT");
        return request;
    }).contentType(MediaType.APPLICATION_JSON).with(user));
}
Also used : OperationResult(org.eclipse.vorto.repository.web.api.v1.dto.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) GsonBuilder(com.google.gson.GsonBuilder) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapperFactory(org.eclipse.vorto.plugin.generator.adapter.ObjectMapperFactory) Gson(com.google.gson.Gson) VortoRepository(org.eclipse.vorto.repository.web.VortoRepository) SpringRunner(org.springframework.test.context.junit4.SpringRunner) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LocalServerPort(org.springframework.boot.context.embedded.LocalServerPort) MediaType(org.springframework.http.MediaType) UserService(org.eclipse.vorto.repository.services.UserService) WebApplicationContext(org.springframework.web.context.WebApplicationContext) TestPropertySource(org.springframework.test.context.TestPropertySource) ModelId(org.eclipse.vorto.model.ModelId) Sql(org.springframework.test.context.jdbc.Sql) Sets(com.google.common.collect.Sets) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Configuration(org.springframework.context.annotation.Configuration) IOUtils(org.apache.commons.io.IOUtils) SecurityMockMvcConfigurers.springSecurity(org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SecurityMockMvcRequestPostProcessors(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors) java.util(java.util) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) ClassPathResource(org.springframework.core.io.ClassPathResource) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) ModelLink(org.eclipse.vorto.repository.web.api.v1.dto.ModelLink) Value(org.springframework.beans.factory.annotation.Value) MockMvc(org.springframework.test.web.servlet.MockMvc) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) ConfigFileApplicationContextInitializer(org.springframework.boot.test.context.ConfigFileApplicationContextInitializer) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) INotificationService(org.eclipse.vorto.repository.notification.INotificationService) Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) Before(org.junit.Before) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) PolicyEntry(org.eclipse.vorto.repository.core.PolicyEntry) Profile(org.springframework.context.annotation.Profile) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) SecurityMockMvcRequestPostProcessors.user(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user) ModelType(org.eclipse.vorto.model.ModelType) IModelPolicyManager(org.eclipse.vorto.repository.core.IModelPolicyManager) UserRepository(org.eclipse.vorto.repository.repositories.UserRepository) ContextConfiguration(org.springframework.test.context.ContextConfiguration) MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder) Bean(org.springframework.context.annotation.Bean) Assert.assertEquals(org.junit.Assert.assertEquals) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)

Example 58 with ModelId

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

the class GeneratorUrlBuilderTest method getGeneratorUrl.

@Test
public void getGeneratorUrl() {
    final String expected = "https://eclipse.vorto.org/api/v1/generators/eclipseditto/models/com.kolotu.test:SomeModel:1.0.0";
    ModelId modelId = ModelId.fromPrettyFormat("com.kolotu.test:SomeModel:1.0.0");
    String generatorKey = "eclipseditto";
    String result = GeneratorUrlBuilder.getGeneratorUrl(BASE_URL, modelId, generatorKey, null);
    assertEquals(expected, result);
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 59 with ModelId

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

the class ModelRepository method getById.

@Override
public ModelInfo getById(ModelId modelId) {
    final ModelId finalModelId = getLatestModelVersionIfLatestTagIsSet(modelId);
    return doInSession(session -> {
        try {
            ModelIdHelper modelIdHelper = new ModelIdHelper(finalModelId);
            Node folderNode = session.getNode(modelIdHelper.getFullPath());
            return getModelResource(finalModelId, folderNode);
        } catch (PathNotFoundException e) {
            return null;
        } catch (AccessDeniedException e) {
            throw new NotAuthorizedException(finalModelId, e);
        }
    });
}
Also used : ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) ModelId(org.eclipse.vorto.model.ModelId)

Example 60 with ModelId

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

the class ModelRepository method getFileContent.

@Override
public Optional<FileContent> getFileContent(ModelId modelId, Optional<String> fileName) {
    return doInSession(session -> {
        try {
            ModelId finalModelId = getLatestModelVersionIfLatestTagIsSet(modelId);
            ModelIdHelper modelIdHelper = new ModelIdHelper(finalModelId);
            Node folderNode = session.getNode(modelIdHelper.getFullPath());
            Node fileNode;
            if (fileName.isPresent()) {
                fileNode = folderNode.getNode(fileName.get());
            } else {
                if (!folderNode.getNodes(FILE_NODES).hasNext()) {
                    throw new NotAuthorizedException(finalModelId);
                }
                fileNode = (Node) folderNode.getNodes(FILE_NODES).next();
            }
            Node fileItem = (Node) fileNode.getPrimaryItem();
            InputStream is = fileItem.getProperty(JCR_DATA).getBinary().getStream();
            final String fileContent = IOUtils.toString(is);
            return Optional.of(new FileContent(fileNode.getName(), fileContent.getBytes()));
        } catch (PathNotFoundException e) {
            return Optional.empty();
        } catch (IOException e) {
            throw new FatalModelRepositoryException("Something went wrong accessing the repository", e);
        } catch (AccessDeniedException e) {
            throw new NotAuthorizedException(modelId, e);
        }
    });
}
Also used : ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) IOException(java.io.IOException) ModelId(org.eclipse.vorto.model.ModelId)

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