Search in sources :

Example 1 with Function

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

the class FunctionFacadeIT method createLinkWithAttribute.

private LinkType createLinkWithAttribute(String name, List<String> collectionIds, String... attributeIds) {
    List<Attribute> attributes = Arrays.stream(attributeIds).map(attributeId -> new Attribute(attributeId, attributeId, null, null, null, new Function("const lumeerko", "", "", 0, false), 1, null)).collect(Collectors.toList());
    LinkType linkType = new LinkType(name, collectionIds, attributes, null, null, null);
    return linkTypeDao.createLinkType(linkType);
}
Also used : UserDao(io.lumeer.storage.api.dao.UserDao) Arrays(java.util.Arrays) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) RunWith(org.junit.runner.RunWith) Deque(java.util.Deque) Function(io.lumeer.api.model.function.Function) GroupDao(io.lumeer.storage.api.dao.GroupDao) ArrayList(java.util.ArrayList) WorkspaceKeeper(io.lumeer.core.WorkspaceKeeper) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Role(io.lumeer.api.model.Role) Assertions(org.assertj.core.api.Assertions) FunctionTask(io.lumeer.core.task.FunctionTask) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) Permission(io.lumeer.api.model.Permission) RoleType(io.lumeer.api.model.RoleType) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) DataDocument(io.lumeer.engine.api.data.DataDocument) Permissions(io.lumeer.api.model.Permissions) Document(io.lumeer.api.model.Document) Set(java.util.Set) Test(org.junit.Test) FunctionRow(io.lumeer.api.model.function.FunctionRow) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) LinkType(io.lumeer.api.model.LinkType) Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) List(java.util.List) IntegrationTestBase(io.lumeer.engine.IntegrationTestBase) FunctionDao(io.lumeer.storage.api.dao.FunctionDao) Attribute(io.lumeer.api.model.Attribute) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Function(io.lumeer.api.model.function.Function) Attribute(io.lumeer.api.model.Attribute) LinkType(io.lumeer.api.model.LinkType)

Example 2 with Function

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

the class FunctionTask method process.

@Override
public void process(final TaskExecutor taskExecutor, final ChangesTracker changesTracker) {
    if (daoContextSnapshot.getSelectedWorkspace() != null && daoContextSnapshot.getSelectedWorkspace().getOrganization().isPresent() && daoContextSnapshot.getSelectedWorkspace().getProject().isPresent()) {
        log.info(String.format("Running function task on %s/%s > Resource '%s', Attribute '%s'.", daoContextSnapshot.getSelectedWorkspace().getOrganization().get().getCode(), daoContextSnapshot.getSelectedWorkspace().getProject().get().getCode(), collection != null ? collection.getName() : linkType.getName(), attribute.getName()));
    }
    if (documents != null && collection != null) {
        getDocumentsWithData(collection, documents).forEach(document -> {
            originalDocuments.put(document.getId(), new Document(document));
            final FunctionTaskExecutor executor = new FunctionTaskExecutor(this, collection, document);
            changesTracker.merge(executor.execute(taskExecutor));
        });
    } else if (linkType != null && linkInstances != null) {
        getLinkInstancesWithData(linkType, linkInstances).forEach(linkInstance -> {
            originalLinkInstances.put(linkInstance.getId(), new LinkInstance(linkInstance));
            final FunctionTaskExecutor executor = new FunctionTaskExecutor(this, linkType, linkInstance);
            changesTracker.merge(executor.execute(taskExecutor));
        });
    }
    if (parent != null) {
        parent.process(taskExecutor, changesTracker);
    }
}
Also used : ChangesTracker(io.lumeer.core.task.executor.ChangesTracker) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Set(java.util.Set) HashMap(java.util.HashMap) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) Function(io.lumeer.api.model.function.Function) LinkType(io.lumeer.api.model.LinkType) FunctionTaskExecutor(io.lumeer.core.task.executor.FunctionTaskExecutor) HashSet(java.util.HashSet) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) List(java.util.List) Map(java.util.Map) Attribute(io.lumeer.api.model.Attribute) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) FunctionTaskExecutor(io.lumeer.core.task.executor.FunctionTaskExecutor) LinkInstance(io.lumeer.api.model.LinkInstance) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document)

Example 3 with Function

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

the class AttributeCodec method convertFromDocument.

public static Attribute convertFromDocument(final Document document) {
    String id = document.getString(ID);
    String name = document.getString(NAME);
    String description = document.getString(DESCRIPTION);
    Constraint constraint = ConstraintCodec.convertFromDocument(document.get(CONSTRAINT, Document.class));
    AttributeLock lock = AttributeLockCodec.convertFromDocument(document.get(LOCK, Document.class));
    Function function = FunctionCodec.convertFromDocument(document.get(FUNCTION, Document.class));
    Integer usageCount = document.getInteger(USAGE_COUNT);
    Boolean suggestValues = document.getBoolean(SUGGEST_VALUES);
    return new Attribute(id, name, description, constraint, lock, function, usageCount, suggestValues);
}
Also used : Function(io.lumeer.api.model.function.Function) Constraint(io.lumeer.api.model.Constraint) Attribute(io.lumeer.api.model.Attribute) AttributeLock(io.lumeer.api.model.AttributeLock) Document(org.bson.Document)

Aggregations

Attribute (io.lumeer.api.model.Attribute)3 Function (io.lumeer.api.model.function.Function)3 Collection (io.lumeer.api.model.Collection)2 Document (io.lumeer.api.model.Document)2 LinkInstance (io.lumeer.api.model.LinkInstance)2 LinkType (io.lumeer.api.model.LinkType)2 DataDocument (io.lumeer.engine.api.data.DataDocument)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 AttributeLock (io.lumeer.api.model.AttributeLock)1 Constraint (io.lumeer.api.model.Constraint)1 Group (io.lumeer.api.model.Group)1 Organization (io.lumeer.api.model.Organization)1 Permission (io.lumeer.api.model.Permission)1 Permissions (io.lumeer.api.model.Permissions)1 Project (io.lumeer.api.model.Project)1 Role (io.lumeer.api.model.Role)1 RoleType (io.lumeer.api.model.RoleType)1