Search in sources :

Example 1 with JsonCollection

use of io.lumeer.api.dto.JsonCollection in project engine by Lumeer.

the class LinkInstanceFacadeIT method configureLinkInstances.

@Before
public void configureLinkInstances() {
    JsonOrganization organization = new JsonOrganization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new JsonPermissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(storedOrganization);
    User user = new User(USER);
    userDao.createUser(user);
    JsonProject project = new JsonProject();
    project.setPermissions(new JsonPermissions());
    project.setCode(PROJECT_CODE);
    Project storedProject = projectDao.createProject(project);
    workspaceKeeper.setWorkspace(ORGANIZATION_CODE, PROJECT_CODE);
    collectionDao.setProject(storedProject);
    JsonPermissions collectionPermissions = new JsonPermissions();
    collectionPermissions.updateUserPermissions(new JsonPermission(USER, Project.ROLES.stream().map(Role::toString).collect(Collectors.toSet())));
    JsonCollection jsonCollection = new JsonCollection("col1", "col1", "icon", "color", collectionPermissions);
    jsonCollection.setDocumentsCount(0);
    String collection1 = collectionDao.createCollection(jsonCollection).getId();
    JsonCollection jsonCollection2 = new JsonCollection("col2", "col2", "icon", "color", collectionPermissions);
    jsonCollection.setDocumentsCount(0);
    String collection2 = collectionDao.createCollection(jsonCollection2).getId();
    LinkType linkType = new LinkType(null, NAME, Arrays.asList(collection1, collection2), ATTRIBUTES);
    linkTypeId1 = linkTypeDao.createLinkType(linkType).getId();
    LinkType linkType2 = new LinkType(null, NAME2, Arrays.asList(collection1, collection2), ATTRIBUTES);
    linkTypeId2 = linkTypeDao.createLinkType(linkType2).getId();
    documentIdsColl1.clear();
    for (int i = 0; i < 3; i++) {
        documentIdsColl1.add(createDocument(collection1).getId());
    }
    documentIdsColl2.clear();
    for (int i = 0; i < 3; i++) {
        documentIdsColl2.add(createDocument(collection2).getId());
    }
}
Also used : JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) LinkType(io.lumeer.api.model.LinkType) JsonCollection(io.lumeer.api.dto.JsonCollection) JsonProject(io.lumeer.api.dto.JsonProject) Before(org.junit.Before)

Example 2 with JsonCollection

use of io.lumeer.api.dto.JsonCollection in project engine by Lumeer.

the class LinkTypeFacadeIT method configureLinkTypes.

@Before
public void configureLinkTypes() {
    JsonOrganization organization = new JsonOrganization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new JsonPermissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(storedOrganization);
    User user = new User(USER);
    userDao.createUser(user);
    JsonProject project = new JsonProject();
    project.setPermissions(new JsonPermissions());
    project.setCode(PROJECT_CODE);
    Project storedProject = projectDao.createProject(project);
    workspaceKeeper.setWorkspace(ORGANIZATION_CODE, PROJECT_CODE);
    collectionDao.setProject(storedProject);
    collectionIds.clear();
    for (String name : COLLECTION_NAMES) {
        JsonPermissions collectionPermissions = new JsonPermissions();
        collectionPermissions.updateUserPermissions(new JsonPermission(USER, Project.ROLES.stream().map(Role::toString).collect(Collectors.toSet())));
        JsonCollection jsonCollection = new JsonCollection(name, name, COLLECTION_ICON, COLLECTION_COLOR, collectionPermissions);
        jsonCollection.setDocumentsCount(0);
        collectionIds.add(collectionDao.createCollection(jsonCollection).getId());
    }
}
Also used : JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) JsonCollection(io.lumeer.api.dto.JsonCollection) JsonProject(io.lumeer.api.dto.JsonProject) Before(org.junit.Before)

Example 3 with JsonCollection

use of io.lumeer.api.dto.JsonCollection in project engine by Lumeer.

the class CollectionServiceIT method testCreateCollection.

@Test
public void testCreateCollection() {
    Collection collection = prepareCollection(CODE);
    Entity entity = Entity.json(collection);
    Response response = client.target(COLLECTIONS_URL).request(MediaType.APPLICATION_JSON).buildPost(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    JsonCollection returnedCollection = response.readEntity(JsonCollection.class);
    assertThat(returnedCollection).isNotNull();
    assertThat(returnedCollection.getId()).isNotNull();
    Collection storedCollection = collectionDao.getCollectionByCode(CODE);
    assertThat(storedCollection).isNotNull();
    assertThat(returnedCollection.getId()).isEqualTo(storedCollection.getId());
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(storedCollection.getCode()).isEqualTo(CODE);
    assertions.assertThat(storedCollection.getName()).isEqualTo(NAME);
    assertions.assertThat(storedCollection.getIcon()).isEqualTo(ICON);
    assertions.assertThat(storedCollection.getColor()).isEqualTo(COLOR);
    assertions.assertThat(storedCollection.getPermissions().getUserPermissions()).containsOnly(USER_PERMISSION);
    assertions.assertThat(storedCollection.getPermissions().getGroupPermissions()).isEmpty();
    assertions.assertAll();
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) SoftAssertions(org.assertj.core.api.SoftAssertions) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) JsonCollection(io.lumeer.api.dto.JsonCollection) Test(org.junit.Test)

Example 4 with JsonCollection

use of io.lumeer.api.dto.JsonCollection in project engine by Lumeer.

the class CollectionServiceIT method testGetAllCollections.

@Test
public void testGetAllCollections() {
    createCollection(CODE);
    createCollection(CODE2);
    Response response = client.target(COLLECTIONS_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<JsonCollection> collections = response.readEntity(new GenericType<List<JsonCollection>>() {
    });
    assertThat(collections).extracting(Resource::getCode).containsOnly(CODE, CODE2);
    Permissions permissions1 = collections.get(0).getPermissions();
    assertThat(permissions1).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions1).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions1).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
    Permissions permissions2 = collections.get(1).getPermissions();
    assertThat(permissions2).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions2).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions2).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
}
Also used : Response(javax.ws.rs.core.Response) UserDao(io.lumeer.storage.api.dao.UserDao) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonPermission(io.lumeer.api.dto.JsonPermission) User(io.lumeer.api.model.User) RunWith(org.junit.runner.RunWith) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonCollection(io.lumeer.api.dto.JsonCollection) Resource(io.lumeer.api.model.Resource) JsonPermissions(io.lumeer.api.dto.JsonPermissions) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) MediaType(javax.ws.rs.core.MediaType) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Role(io.lumeer.api.model.Role) JsonAttribute(io.lumeer.api.dto.JsonAttribute) JsonProject(io.lumeer.api.dto.JsonProject) SimplePermission(io.lumeer.core.model.SimplePermission) UriBuilder(javax.ws.rs.core.UriBuilder) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) Permission(io.lumeer.api.model.Permission) View(io.lumeer.api.model.View) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Permissions(io.lumeer.api.model.Permissions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) Project(io.lumeer.api.model.Project) List(java.util.List) Response(javax.ws.rs.core.Response) Attribute(io.lumeer.api.model.Attribute) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Link(javax.ws.rs.core.Link) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) List(java.util.List) JsonCollection(io.lumeer.api.dto.JsonCollection) Test(org.junit.Test)

Example 5 with JsonCollection

use of io.lumeer.api.dto.JsonCollection in project engine by Lumeer.

the class CollectionService method getCollections.

@GET
public List<JsonCollection> getCollections(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize) {
    Pagination pagination = new Pagination(page, pageSize);
    List<Collection> collections = collectionFacade.getCollections(pagination);
    return JsonCollection.convert(collections);
}
Also used : Pagination(io.lumeer.api.model.Pagination) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) GET(javax.ws.rs.GET)

Aggregations

JsonCollection (io.lumeer.api.dto.JsonCollection)13 JsonOrganization (io.lumeer.api.dto.JsonOrganization)9 JsonPermission (io.lumeer.api.dto.JsonPermission)9 JsonPermissions (io.lumeer.api.dto.JsonPermissions)9 JsonProject (io.lumeer.api.dto.JsonProject)9 Organization (io.lumeer.api.model.Organization)9 Project (io.lumeer.api.model.Project)9 User (io.lumeer.api.model.User)9 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)9 Before (org.junit.Before)9 Collection (io.lumeer.api.model.Collection)5 Response (javax.ws.rs.core.Response)4 Test (org.junit.Test)4 LinkType (io.lumeer.api.model.LinkType)2 Entity (javax.ws.rs.client.Entity)2 SoftAssertions (org.assertj.core.api.SoftAssertions)2 JsonAttribute (io.lumeer.api.dto.JsonAttribute)1 Attribute (io.lumeer.api.model.Attribute)1 Pagination (io.lumeer.api.model.Pagination)1 Permission (io.lumeer.api.model.Permission)1