public String getPrefix() { String data = getStart().getData(); return data.substring(0, data.length() - 1); } }
public void setStatementMetadataProperties(final Set<RyaURI> metadataProperties) { final String[] propArray = new String[metadataProperties.size()]; int i = 0; for(final RyaURI uri: metadataProperties) { propArray[i] = uri.getData(); i++; } setStrings(CONF_STATEMENT_METADATA_PROPERTIES, propArray); }
/** * Converts a {@link RyaURI} to the contained data string. * @param namespace the namespace. * @param the {@link RyaURI} to convert. * @return the data value without the namespace. */ public static String convertRyaUriToString(final String namespace, final RyaURI ryaUri) { return StringUtils.replaceOnce(ryaUri.getData(), namespace, ""); }
private static Bson makeExplicitTypeFilter(final RyaURI typeId) { return Filters.eq(EntityDocumentConverter.EXPLICIT_TYPE_IDS, typeId.getData()); }
private static Bson makeIdFilter(final RyaURI typeId) { return Filters.eq(TypeDocumentConverter.ID, typeId.getData()); } }
private static Bson makeSubjectFilter(final RyaURI subject) { return Filters.eq(EntityDocumentConverter.SUBJECT, subject.getData()); }
public static URI convertURI(RyaURI uri) { return new URIImpl(uri.getData()); }
public static Map<URI, Value> entityToValueMap(final Entity entity) { final Map<URI, Value> map = new LinkedHashMap<>(); for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> entry : entity.getProperties().entrySet()) { for (final Entry<RyaURI, Property> property : entry.getValue().entrySet()) { final RyaURI propertyKey = property.getKey(); final URI uri = new URIImpl(propertyKey.getData()); final Property propertyValue = property.getValue(); final Value value = RyaToRdfConversions.convertValue(propertyValue.getValue()); map.put(uri, value); } } return map; }
@Override public Document toDocument(final Type type) { requireNonNull(type); final Document doc = new Document(); doc.append(ID, type.getId().getData()); final List<String> propertyNames = new ArrayList<>(); type.getPropertyNames().forEach(field -> propertyNames.add(field.getData())); doc.append(PROPERTY_NAMES, propertyNames); return doc; }
@Override public boolean delete(final RyaURI typeId) throws TypeStorageException { requireNonNull(typeId); try { final Document deleted = mongo.getDatabase(ryaInstanceName) .getCollection(COLLECTION_NAME) .findOneAndDelete( makeIdFilter(typeId) ); return deleted != null; } catch(final MongoException e) { throw new TypeStorageException("Could not delete the Type with ID '" + typeId.getData() + "'.", e); } }
@Override public boolean delete(final RyaURI subject) throws EntityStorageException { requireNonNull(subject); try { final Document deleted = mongo.getDatabase(ryaInstanceName) .getCollection(COLLECTION_NAME) .findOneAndDelete( makeSubjectFilter(subject) ); return deleted != null; } catch(final MongoException e) { throw new EntityStorageException("Could not delete the Entity with Subject '" + subject.getData() + "'.", e); } }
@Override public Optional<Entity> get(final RyaURI subject) throws EntityStorageException { requireNonNull(subject); try { final Document document = mongo.getDatabase(ryaInstanceName) .getCollection(COLLECTION_NAME) .find( Filters.eq(EntityDocumentConverter.SUBJECT, subject.getData()) ) .first(); return document == null ? Optional.empty() : Optional.of( ENTITY_CONVERTER.fromDocument(document) ); } catch(final MongoException | DocumentConverterException e) { throw new EntityStorageException("Could not get the Entity with Subject '" + subject.getData() + "'.", e); } }
private static String getShortNameForType(final RyaURI type) throws SmartUriException { final String shortName = new URIImpl(type.getData()).getLocalName(); return shortName; }
private static URI createTypeMapUri(final List<RyaURI> types) throws SmartUriException { final List<NameValuePair> nameValuePairs = new ArrayList<>(); for (final RyaURI type : types) { final String shortName = getShortNameForType(type); nameValuePairs.add(new BasicNameValuePair(type.getData(), shortName)); } final URIBuilder uriBuilder = new URIBuilder(); uriBuilder.addParameters(nameValuePairs); String uriString; try { final java.net.URI uri = uriBuilder.build(); final String queryString = uri.getRawSchemeSpecificPart(); uriString = ENTITY_TYPE_MAP_URN + queryString; } catch (final URISyntaxException e) { throw new SmartUriException("Unable to create type properties for the Smart URI", e); } return new URIImpl(uriString); }
@Override public void create(final Type type) throws TypeStorageException { requireNonNull(type); try { mongo.getDatabase(ryaInstanceName) .getCollection(COLLECTION_NAME) .insertOne(TYPE_CONVERTER.toDocument(type)); } catch(final MongoException e) { throw new TypeStorageException("Failed to create Type with ID '" + type.getId().getData() + "'.", e); } }
@Override public Optional<Type> get(final RyaURI typeId) throws TypeStorageException { requireNonNull(typeId); try { final Document document = mongo.getDatabase(ryaInstanceName) .getCollection(COLLECTION_NAME) .find( makeIdFilter(typeId) ) .first(); return document == null ? Optional.empty() : Optional.of( TYPE_CONVERTER.fromDocument(document) ); } catch(final MongoException | DocumentConverterException e) { throw new TypeStorageException("Could not get the Type with ID '" + typeId.getData() + "'.", e); } }
private int statementSize(final RyaStatement ryaStatement) { final RyaURI subject = ryaStatement.getSubject(); final RyaURI predicate = ryaStatement.getPredicate(); final RyaType object = ryaStatement.getObject(); final RyaURI context = ryaStatement.getContext(); int size = 3 + subject.getData().length() + predicate.getData().length() + object.getData().length(); if (!XMLSchema.ANYURI.equals(object.getDataType())) { size += 2 + object.getDataType().toString().length(); } if (context != null) { size += context.getData().length(); } return size; }
public static Map<URI, Value> propertiesToMap(final Set<Property> properties) { final Map<URI, Value> map = new LinkedHashMap<>(); for (final Property property : properties) { final URI uri = new URIImpl(property.getName().getData()); final Value value = RyaToRdfConversions.convertValue(property.getValue()); map.put(uri, value); } return map; } }
public static String getTripleString(final RyaStatement rs) { checkNotNull(rs); final String subj = rs.getSubject().getData() + TYPE_DELIM + URI_TYPE; final String pred = rs.getPredicate().getData() + TYPE_DELIM + URI_TYPE; final String objData = rs.getObject().getData(); final String objDataType = rs.getObject().getDataType().stringValue(); return subj + DELIM + pred + DELIM + objData + TYPE_DELIM + objDataType; }
private void init() throws RyaTypeResolverException { commonVar = this.getCommonVar(nodes); if(!commonVar.isConstant()) { commonVarName = commonVar.getName(); } else { commonVarName = commonVar.getName().substring(7); } if(hasContext()) { final RyaURI ctxtURI = (RyaURI) RdfToRyaConversions.convertValue(context.getValue()); contextURI = ctxtURI.getData(); } for(int i = 0; i < nodes.size(); i++){ nodeColumnCond[i] = nodeToTextColumn(nodes.get(i), i); } }