Search in sources :

Example 1 with CollectionPurposeType

use of io.lumeer.api.model.CollectionPurposeType in project engine by Lumeer.

the class CollectionCreator method getCollection.

private Collection getCollection(final JSONObject o) {
    final Collection c = new Collection((String) o.get(Collection.CODE), (String) o.get(Collection.NAME), (String) o.get(Collection.ICON), (String) o.get(Collection.COLOR), null);
    c.setDataDescription((String) o.get(Collection.DATA_DESCRIPTION));
    final JSONObject purpose = (JSONObject) o.get(Collection.PURPOSE);
    if (purpose != null) {
        var purposeType = Utils.computeIfNotNull((String) purpose.get(CollectionPurpose.TYPE), CollectionPurposeType::valueOf);
        final JSONObject metaData = (JSONObject) purpose.get(CollectionPurpose.META_DATA);
        final DataDocument dataDocument = new DataDocument();
        if (metaData != null) {
            metaData.forEach((k, v) -> dataDocument.append(templateParser.translateConfig(k, constraintManager).toString(), templateParser.translateConfig(v, constraintManager)));
        }
        c.setPurpose(new CollectionPurpose(purposeType, dataDocument));
    }
    c.setPriority((Long) o.get(Collection.PRIORITY));
    return c;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) JSONObject(org.json.simple.JSONObject) Collection(io.lumeer.api.model.Collection) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) CollectionPurposeType(io.lumeer.api.model.CollectionPurposeType)

Example 2 with CollectionPurposeType

use of io.lumeer.api.model.CollectionPurposeType in project engine by Lumeer.

the class CollectionPurposeCodec method convertFromDocument.

public static CollectionPurpose convertFromDocument(Document bson) {
    if (bson == null) {
        return new CollectionPurpose(CollectionPurposeType.None, new DataDocument());
    }
    String typeString = bson.getString(TYPE);
    CollectionPurposeType purposeType = typeString != null ? CollectionPurposeType.valueOf(typeString) : CollectionPurposeType.None;
    Document metaData = bson.get(META_DATA, Document.class);
    return new CollectionPurpose(purposeType, new DataDocument(metaData == null ? new Document() : metaData));
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) CollectionPurposeType(io.lumeer.api.model.CollectionPurposeType)

Aggregations

CollectionPurpose (io.lumeer.api.model.CollectionPurpose)2 CollectionPurposeType (io.lumeer.api.model.CollectionPurposeType)2 DataDocument (io.lumeer.engine.api.data.DataDocument)2 Collection (io.lumeer.api.model.Collection)1 Document (org.bson.Document)1 JSONObject (org.json.simple.JSONObject)1