All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dheid.roperty.mongodb.ValueDocumentTransformer Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
package io.github.dheid.roperty.mongodb;

import com.parship.roperty.DomainSpecificValueFactory;
import com.parship.roperty.KeyValues;
import com.parship.roperty.KeyValuesFactory;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;

import java.util.List;

public class ValueDocumentTransformer {

    private KeyValuesFactory keyValuesFactory;

    private DomainSpecificValueFactory domainSpecificValueFactory;

    public KeyValues transform(List values, String description) {
        KeyValues keyValues = keyValuesFactory.create(domainSpecificValueFactory);
        keyValues.setDescription(description);

        for (Document valueDocument : values) {
            String pattern = valueDocument.getString(RopertyMongoDbAttribute.PATTERN.getName());
            String[] domainKeyParts;
            if (StringUtils.isEmpty(pattern)) {
                domainKeyParts = new String[0];
            } else {
                domainKeyParts = pattern.split("\\|");
            }
            Object value = valueDocument.get(RopertyMongoDbAttribute.VALUE.getName());
            String changeSet = valueDocument.getString(RopertyMongoDbAttribute.CHANGE_SET.getName());
            if (changeSet == null) {
                keyValues.put(value, domainKeyParts);
            } else {
                keyValues.putWithChangeSet(changeSet, value, domainKeyParts);
            }
        }

        return keyValues;
    }

    public void setKeyValuesFactory(KeyValuesFactory keyValuesFactory) {
        this.keyValuesFactory = keyValuesFactory;
    }

    public void setDomainSpecificValueFactory(DomainSpecificValueFactory domainSpecificValueFactory) {
        this.domainSpecificValueFactory = domainSpecificValueFactory;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy