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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations