use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity in project timbuctoo by HuygensING.
the class AzureVreAuthorizationAccess method deleteVreAuthorizations.
@Override
public void deleteVreAuthorizations(String vreId) throws AuthorizationUnavailableException {
String condition = TableQuery.generateFilterCondition("PartitionKey", TableQuery.QueryComparisons.EQUAL, vreId);
TableBatchOperation deletes = new TableBatchOperation();
for (DynamicTableEntity entity : table.execute(TableQuery.from(DynamicTableEntity.class).where(condition))) {
deletes.delete(entity);
}
try {
table.execute(deletes);
} catch (StorageException e) {
LOG.error("deleteVreAuthorizations failed", e);
throw new AuthorizationUnavailableException("Could not delete authorizations");
}
}
use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity in project timbuctoo by HuygensING.
the class JsonProvenanceToRdfPatch method collectReplacements.
public static Map<String, List<CursorQuad>> collectReplacements(JsonNode activity, QuadStore quadStore) {
Map<String, List<CursorQuad>> toReplace = new HashMap<>();
for (JsonNode revision : activity.get(PROV_GENERATES)) {
final JsonNode replacements = revision.get(TIM_REPLACEMENTS);
if (replacements != null) {
String entity = revision.get(PROV_SPECIALIZATION_OF).get(0).get("@id").asText();
List<CursorQuad> quads = new ArrayList<>();
toReplace.put(revision.get("@id").asText(), quads);
for (JsonNode replacement : replacements) {
if (replacement.has(TIM_PREDICATE)) {
final String predicate = replacement.get(TIM_PREDICATE).get(0).get("@value").asText();
try (Stream<CursorQuad> source = quadStore.getQuads(entity, predicate, Direction.OUT, "")) {
source.forEach(quads::add);
}
}
}
}
}
return toReplace;
}
use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity in project timbuctoo by HuygensING.
the class ViewConfigFetcher method makeDefaultViewConfig.
private ArrayList<Map> makeDefaultViewConfig(String collectionUri, Map<String, Type> schema, TypeNameStore typeNameStore) {
ArrayList<Map> result = new ArrayList<>();
Type collectionType = schema.get(collectionUri);
if (collectionType == null) {
LOG.error("The collectionUri " + collectionUri + " does not exist in the schema! (it does contain: [ " + schema.keySet().stream().collect(Collectors.joining(", ")) + " ]");
} else {
result.add(title(path(jsnA(jsnA(jsn("Entity"), jsn("title")), jsnA(jsn("Value"), jsn("value"))))));
final String collectionGraphqlTypeWithoutDataSet = typeNameStore.makeGraphQlname(collectionUri);
for (Predicate predicate : collectionType.getPredicates()) {
final String predicateAsGraphqlProp = typeNameStore.makeGraphQlnameForPredicate(predicate.getName(), predicate.getDirection(), predicate.isList());
ArrayNode predicateReference = jsnA(jsnA(jsn(collectionGraphqlTypeWithoutDataSet), jsn(predicateAsGraphqlProp)));
if (predicate.isList()) {
predicateReference.add(jsnA(jsn("items"), jsn("items")));
}
String title = "";
if (predicate.getDirection() == Direction.IN) {
title = "⬅︎ ";
}
title += typeNameStore.shorten(predicate.getName());
if (predicate.getReferenceTypes().values().stream().anyMatch(x -> x > 0)) {
// it's at least sometimes a link
result.add(keyValue(title, internalLink(path(pushImm(predicateReference, jsnA(jsn("Entity"), jsn("uri")))), path(pushImm(predicateReference, jsnA(jsn("Entity"), jsn("title")), jsnA(jsn("Value"), jsn("value")))))));
}
if (predicate.getValueTypes().values().stream().anyMatch(x -> x > 0)) {
// it's at least sometimes a normal value
result.add(keyValue(title, path(pushImm(predicateReference, jsnA(jsn("Value"), jsn("value"))))));
}
}
}
return result;
}
use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity in project timbuctoo by HuygensING.
the class ViewConfigMutation method get.
@Override
public Object get(DataFetchingEnvironment env) {
String collectionUri = env.getArgument("collectionUri");
Object viewConfig = env.getArgument("viewConfig");
DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
try {
MutationHelpers.addMutation(dataSet, new PredicateMutation().entity(collectionUri, replace(HAS_VIEW_CONFIG, value(OBJECT_MAPPER.writeValueAsString(viewConfig)))));
return viewConfig;
} catch (LogStorageFailedException | InterruptedException | ExecutionException | JsonProcessingException e) {
throw new RuntimeException(e);
}
}
use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity in project timbuctoo by HuygensING.
the class EntityToJsonMapper method mapEntity.
public ObjectNode mapEntity(Collection collection, ReadEntity entity, boolean withRelations, ExtraEntityMappingOptions extraEntityMappingOptions, ExtraRelationMappingOptions relationMappingOptions) {
final ObjectNode mappedEntity = JsonNodeFactory.instance.objectNode();
String id = entity.getId().toString();
mappedEntity.set("@type", jsn(collection.getEntityTypeName()));
mappedEntity.set("_id", jsn(id));
mappedEntity.set("^rev", jsn(entity.getRev()));
mappedEntity.set("^deleted", jsn(entity.getDeleted()));
mappedEntity.set("^pid", jsn(entity.getPid()));
if (entity.getRdfUri() != null) {
mappedEntity.set("^rdfUri", jsn(entity.getRdfUri().toString()));
}
mappedEntity.set("^rdfAlternatives", jsnA(entity.getRdfAlternatives().stream().map(JsonBuilder::jsn)));
JsonNode variationRefs = jsnA(entity.getTypes().stream().map(type -> {
ObjectNode variationRef = jsnO();
variationRef.set("id", jsn(id));
variationRef.set("type", jsn(type));
return variationRef;
}));
mappedEntity.set("@variationRefs", variationRefs);
Change modified = entity.getModified();
mappedEntity.set("^modified", mapChange(modified));
Change created = entity.getCreated();
mappedEntity.set("^created", mapChange(created));
// translate TimProperties to Json
JsonPropertyConverter jsonPropertyConverter = new JsonPropertyConverter(collection);
entity.getProperties().forEach(prop -> {
try {
Tuple<String, JsonNode> convertedProperty = prop.convert(jsonPropertyConverter);
mappedEntity.set(convertedProperty.getLeft(), convertedProperty.getRight());
} catch (IOException e) {
LOG.error(databaseInvariant, propConversionErrorMessage(id, prop));
LOG.error("Exception message: {}", e.getMessage());
LOG.debug("Stack trace", e);
}
});
if (!Strings.isNullOrEmpty(entity.getDisplayName())) {
mappedEntity.set("@displayName", jsn(entity.getDisplayName()));
}
extraEntityMappingOptions.execute(entity, mappedEntity);
if (withRelations) {
mappedEntity.set("@relationCount", jsn(entity.getRelations().size()));
mappedEntity.set("@relations", mapRelations(entity.getRelations(), relationMappingOptions));
}
return mappedEntity;
}
Aggregations