use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class SBOLReader method parseCollection.
/**
* @param SBOLDoc
* @param topLevel
* @return
* @throws SBOLValidationException if either of the following conditions is satisfied:
* <ul>
* <li>any of the following SBOL validation rules was violated:
* 10202, 10203, 10204, 10206, 10208, 10212, 10213, 12102; or</li>
* <li>an SBOL validation rule violation occurred in the following constructor or methods:
* <ul>
* <li>{@link Collection#Collection(URI)}, </li>
* <li>{@link Collection#setDisplayId(String)}, </li>
* <li>{@link Collection#setVersion(String)}, </li>
* <li>{@link Collection#setMembers(Set)}, </li>
* <li>{@link Collection#setWasDerivedFrom(URI)}, </li>
* <li>{@link Identified#setAnnotations(List)}, or</li>
* <li>{@link SBOLDocument#addCollection(Collection)}.</li>
* </ul>
* </li>
* </ul>
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Collection parseCollection(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
// URIcompliance.extractDisplayId(topLevel.getIdentity());
String displayId = null;
String name = null;
String description = null;
// URI.create(URIcompliance.extractPersistentId(topLevel.getIdentity()));
URI persistentIdentity = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
Set<URI> attachments = new HashSet<>();
Set<URI> members = new HashSet<>();
List<Annotation> annotations = new ArrayList<>();
for (NamedProperty<QName> namedProperty : topLevel.getProperties()) {
if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-10203", topLevel.getIdentity());
}
persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} else if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-10206", topLevel.getIdentity());
}
version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
} else if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-10204", topLevel.getIdentity());
}
displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
} else if (namedProperty.getName().equals(Sbol2Terms.Collection.hasMembers)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-12102", topLevel.getIdentity());
}
members.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getValue() instanceof NestedDocument) {
if (((IdentifiableDocument) namedProperty).getType().equals(Sbol2Terms.Collection.Collection))
parseCollection(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.ModuleDefinition.ModuleDefinition))
parseModuleDefinition(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Model.Model))
parseModel(SBOLDoc, (IdentifiableDocument) namedProperty);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Sequence.Sequence))
parseSequence(SBOLDoc, (IdentifiableDocument) namedProperty);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.ComponentDefinition.ComponentDefinition))
parseComponentDefinition(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.CombinatorialDerivation.CombinatorialDerivation))
parseCombinatorialDerivation(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Implementation.Implementation))
parseImplementation(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Attachment.Attachment))
parseAttachment(SBOLDoc, (IdentifiableDocument) namedProperty);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Activity.Activity))
parseActivity(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Agent.Agent))
parseAgent(SBOLDoc, (IdentifiableDocument) namedProperty);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Plan.Plan))
parsePlan(SBOLDoc, (IdentifiableDocument) namedProperty);
else
parseGenericTopLevel(SBOLDoc, (IdentifiableDocument) namedProperty);
} else {
throw new SBOLValidationException("sbol-12102", topLevel.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-10212", topLevel.getIdentity());
}
name = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
} else if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-10213", topLevel.getIdentity());
}
description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
} else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-10208", topLevel.getIdentity());
}
wasDerivedFroms.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-10221", topLevel.getIdentity());
}
wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getName().equals(Sbol2Terms.TopLevel.hasAttachment)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
}
attachments.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getValue() instanceof IdentifiableDocument) {
if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.Attachment.Attachment)) {
Attachment attachment = parseAttachment(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue());
attachments.add(attachment.getIdentity());
} else {
throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
}
} else {
annotations.add(new Annotation(namedProperty));
}
}
Collection c = new Collection(topLevel.getIdentity());
if (displayId != null)
c.setDisplayId(displayId);
if (version != null)
c.setVersion(version);
if (persistentIdentity != null)
c.setPersistentIdentity(persistentIdentity);
if (!members.isEmpty())
c.setMembers(members);
if (name != null)
c.setName(name);
if (description != null)
c.setDescription(description);
c.setWasDerivedFroms(wasDerivedFroms);
c.setWasGeneratedBys(wasGeneratedBys);
c.setAttachments(attachments);
if (!annotations.isEmpty())
c.setAnnotations(annotations);
Collection oldC = SBOLDoc.getCollection(topLevel.getIdentity());
if (oldC == null) {
SBOLDoc.addCollection(c);
} else {
if (!c.equals(oldC)) {
throw new SBOLValidationException("sbol-10202", c);
}
}
return c;
}
use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class ComponentDefinition method createSequenceAnnotation.
/**
* Creates a child sequence annotation for this component definition with the given arguments,
* and then adds to this component definition's list of sequence annotations.
*
* @param displayId the display ID of the sequence annotation to be created
* @param location the location of the sequence annotation to be created
* @return the created sequence annotation
* @throws SBOLValidationException if any of the following condition is satisfied:
* <ul>
* <li>an SBOL validation rule violation occurred in {@link URIcompliance#createCompliantURI(String, String, String)};</li>
* <li>an SBOL validation rule violation occurred in {@link #createSequenceAnnotation(URI, Set)};</li>
* <li>an SBOL validation rule violation occurred in {@link SequenceAnnotation#setDisplayId(String)}; or</li>
* <li>an SBOL validation rule violation occurred in {@link SequenceAnnotation#setVersion(String)}.</li>
* </ul>
*/
private SequenceAnnotation createSequenceAnnotation(String displayId, Location location) throws SBOLValidationException {
String URIprefix = this.getPersistentIdentity().toString();
String version = this.getVersion();
URI newSequenceAnnotationURI = createCompliantURI(URIprefix, displayId, version);
Set<Location> locations = new HashSet<>();
locations.add(location);
SequenceAnnotation sa = createSequenceAnnotation(newSequenceAnnotationURI, locations);
sa.setPersistentIdentity(createCompliantURI(URIprefix, displayId, ""));
sa.setDisplayId(displayId);
sa.setVersion(version);
return sa;
}
use of org.sbolstandard.core2.Annotation in project zipkin by openzipkin.
the class BulkIndexWriter method addSearchFields.
static void addSearchFields(Span span, JsonGenerator writer) throws IOException {
long timestampMillis = span.timestampAsLong() / 1000L;
if (timestampMillis != 0L)
writer.writeNumberField("timestamp_millis", timestampMillis);
if (!span.tags().isEmpty() || !span.annotations().isEmpty()) {
writer.writeArrayFieldStart("_q");
for (Annotation a : span.annotations()) {
if (a.value().length() > SHORT_STRING_LENGTH)
continue;
writer.writeString(a.value());
}
for (Map.Entry<String, String> tag : span.tags().entrySet()) {
int length = tag.getKey().length() + tag.getValue().length() + 1;
if (length > SHORT_STRING_LENGTH)
continue;
// search is possible by key alone
writer.writeString(tag.getKey());
writer.writeString(tag.getKey() + "=" + tag.getValue());
}
writer.writeEndArray();
}
}
use of org.sbolstandard.core2.Annotation in project zipkin by openzipkin.
the class CassandraUtil method annotationQuery.
/**
* Returns a set of annotation getValues and tags joined on equals, delimited by ░
*
* <p>Values over {@link RecyclableBuffers#SHORT_STRING_LENGTH} are not considered. Zipkin's
* {@link QueryRequest#annotationQuery()} are equals match. Not all values are lookup values. For
* example, {@code sql.query} isn't something that is likely to be looked up by value and indexing
* that could add a potentially kilobyte partition key on {@link Schema#TABLE_SPAN}
*
* @see QueryRequest#annotationQuery()
*/
@Nullable
static String annotationQuery(Span span) {
if (span.annotations().isEmpty() && span.tags().isEmpty())
return null;
// as very unlikely to be in the query
char delimiter = '░';
StringBuilder result = new StringBuilder().append(delimiter);
for (Annotation a : span.annotations()) {
if (a.value().length() > SHORT_STRING_LENGTH)
continue;
result.append(a.value()).append(delimiter);
}
for (Map.Entry<String, String> tag : span.tags().entrySet()) {
if (tag.getValue().length() > SHORT_STRING_LENGTH)
continue;
// search is possible by key alone
result.append(tag.getKey()).append(delimiter);
result.append(tag.getKey()).append('=').append(tag.getValue()).append(delimiter);
}
return result.length() == 1 ? null : result.toString();
}
use of org.sbolstandard.core2.Annotation in project zipkin by openzipkin.
the class V2SpanWriter method sizeInBytes.
@Override
public int sizeInBytes(Span value) {
// {"traceId":""
int sizeInBytes = 13;
sizeInBytes += value.traceId().length();
if (value.parentId() != null) {
// ,"parentId":"0123456789abcdef"
sizeInBytes += 30;
}
// ,"id":"0123456789abcdef"
sizeInBytes += 24;
if (value.kind() != null) {
// ,"kind":""
sizeInBytes += 10;
sizeInBytes += value.kind().name().length();
}
if (value.name() != null) {
// ,"name":""
sizeInBytes += 10;
sizeInBytes += jsonEscapedSizeInBytes(value.name());
}
if (value.timestampAsLong() != 0L) {
// ,"timestamp":
sizeInBytes += 13;
sizeInBytes += asciiSizeInBytes(value.timestampAsLong());
}
if (value.durationAsLong() != 0L) {
// ,"duration":
sizeInBytes += 12;
sizeInBytes += asciiSizeInBytes(value.durationAsLong());
}
if (value.localEndpoint() != null) {
// ,"localEndpoint":
sizeInBytes += 17;
sizeInBytes += endpointSizeInBytes(value.localEndpoint(), false);
}
if (value.remoteEndpoint() != null) {
// ,"remoteEndpoint":
sizeInBytes += 18;
sizeInBytes += endpointSizeInBytes(value.remoteEndpoint(), false);
}
if (!value.annotations().isEmpty()) {
// ,"annotations":[]
sizeInBytes += 17;
int length = value.annotations().size();
// comma to join elements
if (length > 1)
sizeInBytes += length - 1;
for (int i = 0; i < length; i++) {
Annotation a = value.annotations().get(i);
sizeInBytes += annotationSizeInBytes(a.timestamp(), a.value(), 0);
}
}
if (!value.tags().isEmpty()) {
// ,"tags":{}
sizeInBytes += 10;
int tagCount = value.tags().size();
// comma to join elements
if (tagCount > 1)
sizeInBytes += tagCount - 1;
for (Map.Entry<String, String> entry : value.tags().entrySet()) {
// "":""
sizeInBytes += 5;
sizeInBytes += jsonEscapedSizeInBytes(entry.getKey());
sizeInBytes += jsonEscapedSizeInBytes(entry.getValue());
}
}
if (Boolean.TRUE.equals(value.debug())) {
// ,"debug":true
sizeInBytes += 13;
}
if (Boolean.TRUE.equals(value.shared())) {
// ,"shared":true
sizeInBytes += 14;
}
// }
return ++sizeInBytes;
}
Aggregations