Search in sources :

Example 6 with JsonAttribute

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

the class CollectionFacadeIT method testUpdateCollectionAttributeAdd.

@Test
public void testUpdateCollectionAttributeAdd() {
    Collection collection = createCollection(CODE);
    assertThat(collection.getAttributes()).isEmpty();
    JsonAttribute attribute = new JsonAttribute(ATTRIBUTE_NAME, ATTRIBUTE_FULLNAME, ATTRIBUTE_CONSTRAINTS, ATTRIBUTE_COUNT);
    collectionFacade.updateCollectionAttribute(collection.getId(), ATTRIBUTE_FULLNAME, attribute);
    collection = collectionDao.getCollectionByCode(CODE);
    assertThat(collection).isNotNull();
    assertThat(collection.getAttributes()).hasSize(1);
    Attribute storedAttribute = collection.getAttributes().iterator().next();
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(storedAttribute.getName()).isEqualTo(ATTRIBUTE_NAME);
    assertions.assertThat(storedAttribute.getFullName()).isEqualTo(ATTRIBUTE_FULLNAME);
    assertions.assertThat(storedAttribute.getConstraints()).isEqualTo(ATTRIBUTE_CONSTRAINTS);
    assertions.assertThat(storedAttribute.getUsageCount()).isEqualTo(ATTRIBUTE_COUNT);
    assertions.assertAll();
}
Also used : JsonAttribute(io.lumeer.api.dto.JsonAttribute) Attribute(io.lumeer.api.model.Attribute) SoftAssertions(org.assertj.core.api.SoftAssertions) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) JsonAttribute(io.lumeer.api.dto.JsonAttribute) Test(org.junit.Test)

Example 7 with JsonAttribute

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

the class LinkTypeCodec method decode.

@Override
public LinkType decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    String id = bson.getObjectId(ID).toHexString();
    String name = bson.getString(NAME);
    List<String> collectionCodes = bson.get(COLLECTION_IDS, List.class);
    List<JsonAttribute> attributes = new ArrayList<Document>(bson.get(ATTRIBUTES, List.class)).stream().map(AttributeCodec::convertFromDocument).collect(Collectors.toList());
    return new LinkType(id, name, collectionCodes, attributes);
}
Also used : JsonAttribute(io.lumeer.api.dto.JsonAttribute) Document(org.bson.Document) LinkType(io.lumeer.api.model.LinkType)

Example 8 with JsonAttribute

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

the class CollectionServiceIT method testUpdateCollectionAttribute.

@Test
public void testUpdateCollectionAttribute() {
    Collection collection = createCollection(CODE);
    assertThat(collection.getAttributes()).hasSize(1);
    JsonAttribute updatedAttribute = new JsonAttribute(ATTRIBUTE_NAME, ATTRIBUTE_FULLNAME2, ATTRIBUTE_CONSTRAINTS, ATTRIBUTE_COUNT);
    Entity entity = Entity.json(updatedAttribute);
    Response response = client.target(COLLECTIONS_URL).path(collection.getId()).path("attributes").path(ATTRIBUTE_FULLNAME).request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    JsonAttribute attribute = response.readEntity(new GenericType<JsonAttribute>() {
    });
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(attribute.getName()).isEqualTo(ATTRIBUTE_NAME);
    assertions.assertThat(attribute.getFullName()).isEqualTo(ATTRIBUTE_FULLNAME2);
    assertions.assertThat(attribute.getConstraints()).isEqualTo(ATTRIBUTE_CONSTRAINTS);
    assertions.assertThat(attribute.getUsageCount()).isEqualTo(ATTRIBUTE_COUNT);
    assertions.assertAll();
    Collection storedCollection = collectionDao.getCollectionByCode(CODE);
    Set<Attribute> storedAttributes = storedCollection.getAttributes();
    assertThat(storedAttributes).hasSize(1);
    Attribute storedAttribute = storedAttributes.iterator().next();
    assertions = new SoftAssertions();
    assertions.assertThat(storedAttribute.getName()).isEqualTo(ATTRIBUTE_NAME);
    assertions.assertThat(storedAttribute.getFullName()).isEqualTo(ATTRIBUTE_FULLNAME2);
    assertions.assertThat(storedAttribute.getConstraints()).isEqualTo(ATTRIBUTE_CONSTRAINTS);
    assertions.assertThat(storedAttribute.getUsageCount()).isEqualTo(ATTRIBUTE_COUNT);
    assertions.assertAll();
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) JsonAttribute(io.lumeer.api.dto.JsonAttribute) Attribute(io.lumeer.api.model.Attribute) SoftAssertions(org.assertj.core.api.SoftAssertions) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) JsonAttribute(io.lumeer.api.dto.JsonAttribute) Test(org.junit.Test)

Aggregations

JsonAttribute (io.lumeer.api.dto.JsonAttribute)8 Collection (io.lumeer.api.model.Collection)6 JsonCollection (io.lumeer.api.dto.JsonCollection)5 Attribute (io.lumeer.api.model.Attribute)5 Test (org.junit.Test)5 SoftAssertions (org.assertj.core.api.SoftAssertions)4 HashSet (java.util.HashSet)2 List (java.util.List)2 Response (javax.ws.rs.core.Response)2 Document (io.lumeer.api.model.Document)1 LinkType (io.lumeer.api.model.LinkType)1 Pagination (io.lumeer.api.model.Pagination)1 Role (io.lumeer.api.model.Role)1 DocumentUtils (io.lumeer.core.util.DocumentUtils)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 CollectionDao (io.lumeer.storage.api.dao.CollectionDao)1 DataDao (io.lumeer.storage.api.dao.DataDao)1 DocumentDao (io.lumeer.storage.api.dao.DocumentDao)1 LinkInstanceDao (io.lumeer.storage.api.dao.LinkInstanceDao)1 SearchQuery (io.lumeer.storage.api.query.SearchQuery)1