Search in sources :

Example 1 with SimpleResource

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

the class OrganizationCodec method decode.

@Override
public Organization decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    SimpleResource resource = decodeResource(bson, ResourceType.ORGANIZATION);
    Organization organization = new Organization(resource);
    organization.setVersion(resource.getVersion());
    return organization;
}
Also used : Organization(io.lumeer.api.model.Organization) SimpleResource(io.lumeer.api.model.common.SimpleResource) Document(org.bson.Document)

Example 2 with SimpleResource

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

the class ProjectCodec method decode.

@Override
public Project decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    SimpleResource resource = decodeResource(bson, ResourceType.PROJECT);
    TemplateMetadata templateMetadata;
    if (bson.containsKey(TEMPLATE_METADATA)) {
        templateMetadata = TemplateMetadataCodec.convertFromDocument(bson.get(TEMPLATE_METADATA, Document.class));
    } else {
        templateMetadata = null;
    }
    boolean isPublic = bson.getBoolean(IS_PUBLIC, false);
    String templateId = bson.getString(TEMPLATE_ID);
    Project project = new Project(resource, isPublic, templateMetadata);
    project.setVersion(resource.getVersion());
    project.setTemplateId(templateId);
    return project;
}
Also used : Project(io.lumeer.api.model.Project) SimpleResource(io.lumeer.api.model.common.SimpleResource) Document(org.bson.Document) TemplateMetadata(io.lumeer.api.model.TemplateMetadata)

Example 3 with SimpleResource

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

the class ResourceCodec method decodeResource.

protected SimpleResource decodeResource(final Document bson, final ResourceType resourceType) {
    String id = bson.getObjectId(ID).toHexString();
    String code = bson.getString(CODE);
    String name = bson.getString(NAME);
    String icon = bson.getString(ICON);
    String color = bson.getString(COLOR);
    Long version = bson.getLong(VERSION);
    Long order = bson.getLong(PRIORITY);
    String description = bson.getString(DESCRIPTION);
    Permissions permissions;
    if (bson.containsKey(ROLES)) {
        permissions = PermissionsCodec.convertFromDocument(bson.get(ROLES, Document.class));
    } else {
        permissions = PermissionsCodec.convertFromDocumentLegacy(bson.get(PERMISSIONS, Document.class), resourceType);
    }
    Date creationDate = bson.getDate(CREATION_DATE);
    ZonedDateTime creationZonedDate = creationDate != null ? ZonedDateTime.ofInstant(creationDate.toInstant(), ZoneOffset.UTC) : null;
    String createdBy = bson.getString(CREATED_BY);
    Date updateDate = bson.getDate(UPDATE_DATE);
    ZonedDateTime updatedZonedDate = updateDate != null ? ZonedDateTime.ofInstant(updateDate.toInstant(), ZoneOffset.UTC) : null;
    String updatedBy = bson.getString(UPDATED_BY);
    SimpleResource resource = new SimpleResource(code, name, icon, color, description, order, permissions);
    resource.setId(id);
    resource.setVersion(version == null ? 0 : version);
    resource.setCreatedBy(createdBy);
    resource.setCreationDate(creationZonedDate);
    resource.setUpdatedBy(updatedBy);
    resource.setUpdateDate(updatedZonedDate);
    return resource;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Permissions(io.lumeer.api.model.Permissions) SimpleResource(io.lumeer.api.model.common.SimpleResource) Date(java.util.Date)

Example 4 with SimpleResource

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

the class ViewCodec method decode.

@Override
public View decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    SimpleResource resource = decodeResource(bson, ResourceType.VIEW);
    Query query = QueryCodec.convertFromDocument(bson.get(QUERY, Document.class));
    Perspective perspective = decodePerspective(bson);
    Object config = bson.get(CONFIG);
    Object settings = bson.get(SETTINGS);
    String authorId = bson.getString(AUTHOR_ID);
    Date lastTimeUsed = bson.getDate(LAST_TIME_USED);
    List<String> folders = bson.getList(FOLDERS, String.class);
    List<Query> additionalQueries = Collections.emptyList();
    List queriesList = bson.get(ADDITIONAL_QUERIES, List.class);
    if (queriesList != null) {
        additionalQueries = new ArrayList<Document>(queriesList).stream().map(QueryCodec::convertFromDocument).collect(Collectors.toList());
    }
    View view = new View(resource, query, additionalQueries, perspective, config, settings, authorId, folders);
    view.setVersion(resource.getVersion());
    if (lastTimeUsed != null) {
        view.setLastTimeUsed(ZonedDateTime.ofInstant(lastTimeUsed.toInstant(), ZoneOffset.UTC));
    }
    return view;
}
Also used : Query(io.lumeer.api.model.Query) ArrayList(java.util.ArrayList) Document(org.bson.Document) View(io.lumeer.api.model.View) Date(java.util.Date) Perspective(io.lumeer.api.model.Perspective) SimpleResource(io.lumeer.api.model.common.SimpleResource) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with SimpleResource

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

the class CollectionCodec method decode.

@Override
public Collection decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    SimpleResource resource = decodeResource(bson, ResourceType.COLLECTION);
    Set<Attribute> attributes;
    List attributeList = bson.get(ATTRIBUTES, List.class);
    if (attributeList != null) {
        attributes = new ArrayList<Document>(attributeList).stream().map(AttributeCodec::convertFromDocument).collect(Collectors.toSet());
    } else {
        attributes = Collections.emptySet();
    }
    Map<String, Rule> rules = new HashMap<>();
    Document rulesMap = bson.get(RULES, Document.class);
    if (rulesMap != null) {
        rulesMap.forEach((k, v) -> {
            final Rule rule = RuleCodec.convertFromDocument(rulesMap.get(k, Document.class));
            rule.setId(k);
            if (StringUtils.isEmpty(rule.getName())) {
                rule.setName(k);
            }
            rules.put(k, rule);
        });
    }
    Integer lastAttributeNum = bson.getInteger(LAST_ATTRIBUTE_NUM);
    Date lastTimeUsed = bson.getDate(LAST_TIME_USED);
    String defaultAttributeId = bson.getString(DEFAULT_ATTRIBUTE_ID);
    String dataDescription = bson.getString(DATA_DESCRIPTION);
    CollectionPurpose purpose;
    try {
        purpose = CollectionPurposeCodec.convertFromDocument(bson.get(PURPOSE, Document.class));
    } catch (ClassCastException e) {
        purpose = new CollectionPurpose(CollectionPurposeType.None, new DataDocument());
    }
    Collection collection = new Collection(resource, attributes, rules, dataDescription, purpose);
    if (lastTimeUsed != null) {
        collection.setLastTimeUsed(ZonedDateTime.ofInstant(lastTimeUsed.toInstant(), ZoneOffset.UTC));
    }
    collection.setDefaultAttributeId(defaultAttributeId);
    collection.setLastAttributeNum(lastAttributeNum);
    collection.setVersion(resource.getVersion());
    return collection;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Attribute(io.lumeer.api.model.Attribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) Date(java.util.Date) SimpleResource(io.lumeer.api.model.common.SimpleResource) Collection(io.lumeer.api.model.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Rule(io.lumeer.api.model.Rule) CollectionPurpose(io.lumeer.api.model.CollectionPurpose)

Aggregations

SimpleResource (io.lumeer.api.model.common.SimpleResource)5 Document (org.bson.Document)4 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Attribute (io.lumeer.api.model.Attribute)1 Collection (io.lumeer.api.model.Collection)1 CollectionPurpose (io.lumeer.api.model.CollectionPurpose)1 Organization (io.lumeer.api.model.Organization)1 Permissions (io.lumeer.api.model.Permissions)1 Perspective (io.lumeer.api.model.Perspective)1 Project (io.lumeer.api.model.Project)1 Query (io.lumeer.api.model.Query)1 Rule (io.lumeer.api.model.Rule)1 TemplateMetadata (io.lumeer.api.model.TemplateMetadata)1 View (io.lumeer.api.model.View)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 ZonedDateTime (java.time.ZonedDateTime)1 HashMap (java.util.HashMap)1