@Override public StreamingPropertyValue wrap(VideoTranscript value) { InputStream in = new ByteArrayInputStream(value.toJson().toString().getBytes()); StreamingPropertyValue result = new StreamingPropertyValue(in, byte[].class); result.searchIndex(false); return result; }
protected void setIconProperty( Concept concept, File inDir, String glyphIconFileName, String propertyKey, User user, Authorizations authorizations ) throws IOException { if (glyphIconFileName != null) { File iconFile = new File(inDir, glyphIconFileName); if (!iconFile.exists()) { throw new RuntimeException("Could not find icon file: " + iconFile.toString()); } try (InputStream iconFileIn = new FileInputStream(iconFile)) { StreamingPropertyValue value = new StreamingPropertyValue(iconFileIn, byte[].class); value.searchIndex(false); value.store(true); concept.setProperty(propertyKey, value, user, authorizations); } } }
private Object convertStreamingValueJsonToValueObject(File baseDir, String valueString) { JSONObject streamingValueJson = new JSONObject(valueString.substring("streamingValue:".length())); String fileName = streamingValueJson.getString("fileName"); if (baseDir == null) { throw new VisalloException("Could not import streamingValue. No baseDir specified."); } File file = new File(baseDir, fileName); InputStream in; try { if (!file.exists()) { throw new VisalloException("File " + file.getAbsolutePath() + " does not exist."); } in = new FileInputStream(file); } catch (FileNotFoundException ex) { throw new VisalloException("File " + file.getAbsolutePath() + " does not exist."); } StreamingPropertyValue spv = new StreamingPropertyValue(in, byte[].class); spv.searchIndex(false); spv.store(true); return spv; }
@Override public AddSupportingFilesResult addSupportingFiles(VertexBuilder vertexBuilder, File f, Visibility visibility) throws FileNotFoundException { File mappingJsonFile = getMetadataFile(f); if (mappingJsonFile.exists()) { final FileInputStream mappingJsonInputStream = new FileInputStream(mappingJsonFile); StreamingPropertyValue mappingJsonValue = new StreamingPropertyValue(mappingJsonInputStream, byte[].class); mappingJsonValue.searchIndex(false); VisalloProperties.METADATA_JSON.setProperty(vertexBuilder, mappingJsonValue, visibility); return new AddSupportingFilesResult() { @Override public void close() throws IOException { mappingJsonInputStream.close(); } }; } return null; }
@Override protected void addEntityGlyphIconToEntityConcept(Concept entityConcept, byte[] rawImg, Authorizations authorizations) { StreamingPropertyValue raw = new StreamingPropertyValue(new ByteArrayInputStream(rawImg), byte[].class); raw.searchIndex(false); entityConcept.setProperty(OntologyProperties.GLYPH_ICON.getPropertyName(), raw, getSystemUser(), authorizations); graph.flush(); }
StreamingPropertyValue spv = new StreamingPropertyValue(in, byte[].class); spv.store(true); spv.searchIndex(false); return spv; } catch (FileNotFoundException ex) { StreamingPropertyValue spv = new StreamingPropertyValue(in, byte[].class); spv.store(true); spv.searchIndex(false); return spv; default:
@Override public void storeOntologyFile(InputStream in, IRI documentIRI, Authorizations authorizations) { byte[] data; try { data = IOUtils.toByteArray(in); } catch (IOException ex) { throw new VisalloException("Could not read ontology input stream", ex); } String md5 = DigestUtils.md5Hex(data); StreamingPropertyValue value = new StreamingPropertyValue(new ByteArrayInputStream(data), byte[].class); value.searchIndex(false); Vertex rootConceptVertex = ((VertexiumConcept) getRootConcept(PUBLIC)).getVertex(); Property existingProperty = OntologyProperties.ONTOLOGY_FILE.getProperty(rootConceptVertex, documentIRI.toString()); Date modifiedDate = new Date(); Metadata metadata; if (existingProperty == null) { metadata = getMetadata(modifiedDate, getSystemUser(), VISIBILITY.getVisibility()); metadata.add("index", Iterables.size(OntologyProperties.ONTOLOGY_FILE.getProperties(rootConceptVertex)), VISIBILITY.getVisibility()); } else { metadata = existingProperty.getMetadata(); } VisibilityJson visibilityJson = new VisibilityJson(VISIBILITY.getVisibility().getVisibilityString()); try (GraphUpdateContext ctx = graphRepository.beginGraphUpdate(Priority.LOW, getSystemUser(), getAuthorizations(PUBLIC))) { ctx.setPushOnQueue(false); ctx.update(rootConceptVertex, modifiedDate, visibilityJson, rootConceptCtx -> { OntologyProperties.ONTOLOGY_FILE.updateProperty(rootConceptCtx, documentIRI.toString(), value, metadata, VISIBILITY.getVisibility()); OntologyProperties.ONTOLOGY_FILE_MD5.updateProperty(rootConceptCtx, documentIRI.toString(), md5, metadata, VISIBILITY.getVisibility()); }); } }
private void createVertex(String data, String mimeType) throws UnsupportedEncodingException { VertexBuilder v = getGraph().prepareVertex("v1", visibility); StreamingPropertyValue textValue = new StreamingPropertyValue(new ByteArrayInputStream(data.getBytes("UTF-8")), byte[].class); textValue.searchIndex(false); Metadata metadata = new Metadata(); metadata.add(VisalloProperties.MIME_TYPE.getPropertyName(), mimeType, getVisibilityTranslator().getDefaultVisibility()); VisalloProperties.RAW.setProperty(v, textValue, metadata, visibility); v.save(getGraphAuthorizations()); }
rawValue.searchIndex(false); rawValue.store(true);
rawValue.searchIndex(false);
@Test public void testMultipleRaws() throws UnsupportedEncodingException { VertexBuilder v = getGraph().prepareVertex("v1", visibility); StreamingPropertyValue textValue = new StreamingPropertyValue(new ByteArrayInputStream("<html><body>Text1</body></html>".getBytes("UTF-8")), byte[].class); textValue.searchIndex(false); Metadata metadata = new Metadata(); metadata.add(VisalloProperties.MIME_TYPE.getPropertyName(), "text/html", getVisibilityTranslator().getDefaultVisibility()); v.setProperty("http://visallo.org/test#raw1", textValue, metadata, visibility); textValue = new StreamingPropertyValue(new ByteArrayInputStream("<html><body>Text2</body></html>".getBytes("UTF-8")), byte[].class); textValue.searchIndex(false); metadata = new Metadata(); metadata.add(VisalloProperties.MIME_TYPE.getPropertyName(), "text/html", getVisibilityTranslator().getDefaultVisibility()); v.setProperty("http://visallo.org/test#raw2", textValue, metadata, visibility); v.save(getGraphAuthorizations()); Vertex vertex = getGraph().getVertex("v1", getGraphAuthorizations()); run(gpw, createWorkerPrepareData(), vertex); Property text1Property = vertex.getProperty("http://visallo.org/test#text1"); assertTrue(text1Property != null); assertThat(((StreamingPropertyValue) text1Property.getValue()).readToString(), equalTo("Text1")); assertThat(VisalloProperties.TEXT_DESCRIPTION_METADATA.getMetadataValue(text1Property.getMetadata()), equalTo("Text 1")); Property text2Property = vertex.getProperty("http://visallo.org/test#text2"); assertTrue(text2Property != null); assertThat(((StreamingPropertyValue) text2Property.getValue()).readToString(), equalTo("Text2")); assertThat(VisalloProperties.TEXT_DESCRIPTION_METADATA.getMetadataValue(text2Property.getMetadata()), equalTo(null)); }
@Test public void testDifferentKey() throws UnsupportedEncodingException { VertexBuilder v = getGraph().prepareVertex("v1", visibility); StreamingPropertyValue textValue = new StreamingPropertyValue(new ByteArrayInputStream("<html><body>Text1</body></html>".getBytes("UTF-8")), byte[].class); textValue.searchIndex(false); Metadata metadata = new Metadata(); metadata.add(VisalloProperties.MIME_TYPE.getPropertyName(), "text/html", getVisibilityTranslator().getDefaultVisibility()); v.addPropertyValue("key1", "http://visallo.org/test#raw1", textValue, metadata, visibility); v.save(getGraphAuthorizations()); Vertex vertex = getGraph().getVertex("v1", getGraphAuthorizations()); run(gpw, createWorkerPrepareData(), vertex); Property text1Property = vertex.getProperty("key1", "http://visallo.org/test#text1"); assertTrue(text1Property != null); assertThat(((StreamingPropertyValue) text1Property.getValue()).readToString(), equalTo("Text1")); }