use of io.automatiko.engine.api.auth.AccessDeniedException in project automatiko-engine by automatiko-io.
the class CassandraProcessInstances method findByIdOrTag.
@Override
public Collection findByIdOrTag(ProcessInstanceReadMode mode, int status, String... values) {
LOGGER.debug("findByIdOrTag() called for values {}", values);
List<Row> collected = new ArrayList<Row>();
Set<String> distinct = new HashSet<String>();
Select select = selectFrom(config.keyspace().orElse("automatiko"), tableName).column(INSTANCE_ID_FIELD).column(CONTENT_FIELD).column(VERSION_FIELD).column(TAGS_FIELD).whereColumn(STATUS_FIELD).isEqualTo(literal(status));
ResultSet rs = cqlSession.execute(select.build());
rs.all().stream().filter(r -> !distinct.contains(r.getString(INSTANCE_ID_FIELD))).filter(r -> {
if (values == null || values.length == 0) {
return true;
}
Set<String> tags = r.getSet(TAGS_FIELD, String.class);
return Stream.of(values).anyMatch(v -> tags.contains(v));
}).forEach(r -> {
distinct.add(r.getString(INSTANCE_ID_FIELD));
collected.add(r);
});
return collected.stream().map(item -> {
try {
byte[] content = ByteUtils.getArray(item.getByteBuffer(CONTENT_FIELD));
return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, item.getLong(VERSION_FIELD)) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
} catch (AccessDeniedException e) {
return null;
}
}).filter(pi -> pi != null).collect(Collectors.toList());
}
use of io.automatiko.engine.api.auth.AccessDeniedException in project automatiko-engine by automatiko-io.
the class DynamoDBProcessInstances method values.
@Override
public Collection values(ProcessInstanceReadMode mode, int status, int page, int size) {
LOGGER.debug("values() called");
Map<String, AttributeValue> attrValues = new HashMap<String, AttributeValue>();
StringBuilder condition = new StringBuilder();
attrValues.put(":status", AttributeValue.builder().n(String.valueOf(status)).build());
condition.append(STATUS_FIELD + " = :status ");
ScanRequest request = ScanRequest.builder().tableName(tableName).filterExpression(condition.toString()).expressionAttributeValues(attrValues).limit(page * size).build();
return dynamodb.scanPaginator(request).items().stream().map(item -> {
try {
byte[] content = item.get(CONTENT_FIELD).b().asByteArray();
return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, Long.parseLong(item.get(VERSION_FIELD).n())) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
} catch (AccessDeniedException e) {
return null;
}
}).filter(pi -> pi != null).skip(calculatePage(page, size)).limit(size).collect(Collectors.toList());
}
use of io.automatiko.engine.api.auth.AccessDeniedException in project automatiko-engine by automatiko-io.
the class CassandraProcessInstances method values.
@Override
public Collection values(ProcessInstanceReadMode mode, int status, int page, int size) {
LOGGER.debug("values() called");
Select select = selectFrom(config.keyspace().orElse("automatiko"), tableName).column(CONTENT_FIELD).column(VERSION_FIELD).whereColumn(STATUS_FIELD).isEqualTo(literal(status));
ResultSet rs = cqlSession.execute(select.build());
return rs.all().stream().map(item -> {
try {
byte[] content = ByteUtils.getArray(item.getByteBuffer(CONTENT_FIELD));
return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, item.getLong(VERSION_FIELD)) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
} catch (AccessDeniedException e) {
return null;
}
}).filter(pi -> pi != null).skip(calculatePage(page, size)).limit(size).collect(Collectors.toList());
}
use of io.automatiko.engine.api.auth.AccessDeniedException in project automatiko-engine by automatiko-io.
the class DynamoDBProcessInstances method findByIdOrTag.
@Override
public Collection findByIdOrTag(ProcessInstanceReadMode mode, int status, String... values) {
LOGGER.debug("findByIdOrTag() called for values {}", values);
Map<String, AttributeValue> attrValues = new HashMap<String, AttributeValue>();
int counter = 0;
StringBuilder condition = new StringBuilder();
attrValues.put(":status", AttributeValue.builder().n(String.valueOf(status)).build());
condition.append(STATUS_FIELD + "= :status AND ");
for (String value : values) {
attrValues.put(":value" + counter, AttributeValue.builder().s(value).build());
condition.append("contains(" + TAGS_FIELD + ", :value" + counter + ") OR ");
counter++;
}
condition.delete(condition.length() - 4, condition.length());
ScanRequest query = ScanRequest.builder().tableName(tableName).filterExpression(condition.toString()).expressionAttributeValues(attrValues).build();
return dynamodb.scan(query).items().stream().map(item -> {
try {
byte[] content = item.get(CONTENT_FIELD).b().asByteArray();
return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, Long.parseLong(item.get(VERSION_FIELD).n())) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
} catch (AccessDeniedException e) {
return null;
}
}).filter(pi -> pi != null).collect(Collectors.toList());
}
Aggregations