Search in sources :

Example 1 with Sequence

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

the class MongoSequenceDao method resetSequence.

@Override
public synchronized void resetSequence(final String indexName) {
    final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER).upsert(true);
    final Sequence sequence = new Sequence(indexName, 0);
    Bson update = new org.bson.Document("$set", sequence);
    databaseCollection().findOneAndUpdate(eq(SequenceCodec.NAME, indexName), update, options);
}
Also used : FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Sequence(io.lumeer.api.model.Sequence) RemoveSequence(io.lumeer.engine.api.event.RemoveSequence) CreateOrUpdateSequence(io.lumeer.engine.api.event.CreateOrUpdateSequence) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) Bson(org.bson.conversions.Bson)

Example 2 with Sequence

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

the class SequenceCodec method convertFromDocument.

private static Sequence convertFromDocument(final Document bson) {
    String id = bson.get(ID) != null ? bson.getObjectId(ID).toHexString() : null;
    String name = bson.getString(NAME);
    int seq = bson.getInteger(SEQ);
    Sequence sequence = new Sequence(name, seq);
    sequence.setId(id);
    return sequence;
}
Also used : Sequence(io.lumeer.api.model.Sequence)

Example 3 with Sequence

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

the class AbstractContextualTask method sendPushNotifications.

public void sendPushNotifications(final String sequenceName) {
    final Sequence sequence = getDaoContextSnapshot().getSequenceDao().getSequence(sequenceName);
    final Set<String> techManagers = permissionAdapter.getProjectUsersByRole(daoContextSnapshot.getOrganization(), daoContextSnapshot.getProject(), RoleType.TechConfig);
    final List<Event> events = new ArrayList<>();
    techManagers.forEach(manager -> events.add(createEventForSequence(sequence, manager)));
    getPusherClient().trigger(events);
}
Also used : ArrayList(java.util.ArrayList) Event(org.marvec.pusher.data.Event) BackupDataEvent(org.marvec.pusher.data.BackupDataEvent) Sequence(io.lumeer.api.model.Sequence)

Example 4 with Sequence

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

the class SequenceCreator method createSequences.

private void createSequences() {
    final JSONArray sequences = (JSONArray) templateParser.template.get("sequences");
    if (sequences != null) {
        sequences.forEach(seqObj -> {
            var seqJson = (JSONObject) seqObj;
            String name = seqJson.get(Sequence.NAME).toString();
            int seq = ((Long) seqJson.get(Sequence.SEQ)).intValue();
            sequenceFacade.getNextSequenceNumber(name);
            Optional<Sequence> foundSeq = sequenceFacade.getAllSequences().stream().filter(s -> s.getName().equals(name)).findFirst();
            if (foundSeq.isPresent()) {
                var sequence = new Sequence(name, seq);
                sequence.setId(foundSeq.get().getId());
                sequenceFacade.updateSequence(foundSeq.get().getId(), sequence);
            }
        });
    }
}
Also used : JSONObject(org.json.simple.JSONObject) Sequence(io.lumeer.api.model.Sequence) SequenceFacade(io.lumeer.core.facade.SequenceFacade) Optional(java.util.Optional) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) Sequence(io.lumeer.api.model.Sequence)

Example 5 with Sequence

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

the class PusherFacade method removeSequenceNotification.

public void removeSequenceNotification(@Observes final RemoveSequence removeSequence) {
    if (isEnabled()) {
        try {
            Sequence sequence = removeSequence.getSequence();
            Set<String> userIds = permissionAdapter.getProjectUsersByRole(getOrganization(), getProject(), RoleType.TechConfig);
            ResourceId message = new ResourceId(getAppId(), sequence.getId());
            sendNotificationsByUsers(message, userIds, REMOVE_EVENT_SUFFIX);
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to send push notification: ", e);
        }
    }
}
Also used : Sequence(io.lumeer.api.model.Sequence) RemoveSequence(io.lumeer.engine.api.event.RemoveSequence) CreateOrUpdateSequence(io.lumeer.engine.api.event.CreateOrUpdateSequence)

Aggregations

Sequence (io.lumeer.api.model.Sequence)7 CreateOrUpdateSequence (io.lumeer.engine.api.event.CreateOrUpdateSequence)4 RemoveSequence (io.lumeer.engine.api.event.RemoveSequence)4 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)3 ReturnDocument (com.mongodb.client.model.ReturnDocument)2 Document (org.bson.Document)2 Bson (org.bson.conversions.Bson)2 MongoException (com.mongodb.MongoException)1 SequenceFacade (io.lumeer.core.facade.SequenceFacade)1 StorageException (io.lumeer.storage.api.exception.StorageException)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 BackupDataEvent (org.marvec.pusher.data.BackupDataEvent)1 Event (org.marvec.pusher.data.Event)1