org.openrdf.model.impl.ValueFactoryImpl Java Examples

The following examples show how to use org.openrdf.model.impl.ValueFactoryImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WriteStatementsKnowledgeStore.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static public org.openrdf.model.Statement castJenaOpenRdf(com.hp.hpl.jena.rdf.model.Statement jenaStatement, String modelName) {
    org.openrdf.model.Statement statement = null;
    try {
        ValueFactory valueFactory = ValueFactoryImpl.getInstance();
        URI modelURI = valueFactory.createURI(modelName);
        URI subject = valueFactory.createURI(jenaStatement.getSubject().getURI());
        URI sem = valueFactory.createURI(jenaStatement.getPredicate().getURI());
        if (jenaStatement.getObject().isLiteral()) {
            Literal objectLiteral = valueFactory.createLiteral(jenaStatement.getObject().toString());
             statement = valueFactory.createStatement(subject, sem, objectLiteral, modelURI);
        }

        else {
            URI objectUri = valueFactory.createURI(jenaStatement.getObject().asResource().getURI());
             statement = valueFactory.createStatement(subject, sem, objectUri, modelURI);
        }
    } catch (Exception e) {
        System.out.println("jenaStatement.toString() = " + jenaStatement.toString());
        e.printStackTrace();
    }
    return statement;
}
 
Example #2
Source File: ContainerTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public void testRemove() throws Exception {
	Seq list = con.addDesignation(con.getObject(ValueFactoryImpl
			.getInstance().createURI("urn:", "root")), Seq.class);
	list.add("one");
	list.add("two");
	list.add("four");
	list.add(2, "three");
	assertEquals(Arrays.asList("one", "two", "three", "four"), list);
	Iterator<Object> it = list.iterator();
	it.next();
	it.remove();
	assertEquals(Arrays.asList("two", "three", "four"), list);
	it = list.iterator();
	it.next();
	it.next();
	it.remove();
	assertEquals(Arrays.asList("two", "four"), list);
	it = list.iterator();
	it.next();
	it.next();
	it.remove();
	assertEquals(Arrays.asList("two"), list);
}
 
Example #3
Source File: UserGuideTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public void testChainOfResponsibility() throws Exception {
	String agentType = NS + "SupportAgent";
	String userType = NS + "User";
	ObjectRepositoryConfig module = new ObjectRepositoryConfig();
	module.addBehaviour(ITSupportAgent.class, new URIImpl(agentType));
	module.addConcept(SupportAgent.class, new URIImpl(agentType));
	module.addBehaviour(PersonalBehaviour.class);
	module.addConcept(EmailUser.class, new URIImpl(userType));
	module.addConcept(User.class, new URIImpl(userType));
	module.addConcept(EmailMessage.class);
	factory = new ObjectRepositoryFactory().createRepository(module, repository);
	manager = factory.getConnection();

	URI id = ValueFactoryImpl.getInstance().createURI(NS, "E340076");
	manager.addDesignation(manager.getObject(id), SupportAgent.class);
	manager.addDesignation(manager.getObject(id), User.class);

	EmailUser user = (EmailUser) manager.getObject(id);
	user.setUserName("john");
	EmailMessage message = manager.addDesignation(manager.getObjectFactory().createObject(), EmailMessage.class);
	message.setToEmailAddress("[email protected]");
	if (!user.readEmail(message)) {
		fail();
	}
}
 
Example #4
Source File: UserGuideTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public void testStrategy() throws Exception {
	ObjectRepositoryConfig module = new ObjectRepositoryConfig();
	module.addBehaviour(SalesmanBonusBehaviour.class);
	module.addBehaviour(EngineerBonusBehaviour.class);
	module.addConcept(Engineer.class);
	factory = new ObjectRepositoryFactory().createRepository(module, repository);
	manager = factory.getConnection();

	URI id = ValueFactoryImpl.getInstance().createURI(NS, "E340076");
	Engineer eng = manager.addDesignation(manager.getObject(id), Engineer.class);
	eng.setBonusTargetMet(true);
	eng.setSalary(100);

	Employee employee = (Employee) manager.getObject(id);
	double bonus = employee.calculateExpectedBonus(0.05);

	assertEquals("bonus", 5.0, bonus, 0);
}
 
Example #5
Source File: TestFederatedQuery.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read the expected tuple query result from the specified resource
 * 
 * @param queryResource
 * @return
 * @throws RepositoryException
 * @throws IOException
 */
private TupleQueryResult readExpectedTupleQueryResult(final String resultFile)    throws Exception
{
   final TupleQueryResultFormat tqrFormat = QueryResultIO.getParserFormatForFileName(resultFile);

    if (tqrFormat != null) {
       final InputStream in = TestFederatedQuery.class.getResourceAsStream(TEST_RESOURCE_PATH + resultFile);
        try {
           final TupleQueryResultParser parser = QueryResultIO.createParser(tqrFormat);
            parser.setValueFactory(ValueFactoryImpl.getInstance());

            final TupleQueryResultBuilder qrBuilder = new TupleQueryResultBuilder();
            parser.setTupleQueryResultHandler(qrBuilder);

            parser.parse(in);
            return qrBuilder.getQueryResult();
        }
        finally {
            in.close();
        }
    }
    else {
       final Set<Statement> resultGraph = readExpectedGraphQueryResult(resultFile);
        return DAWGTestResultSetUtil.toTupleQueryResult(resultGraph);
    }
}
 
Example #6
Source File: AbstractRMLProcessor.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<Statement> processSubjectTypeMap(SesameDataSet dataset, Resource subject,
		SubjectMap subjectMap, Object node) {
	List<Statement> statements=new LinkedList<>();
	ValueFactory myFactory = ValueFactoryImpl.getInstance();
	
	// Add the type triples
	Set<org.openrdf.model.URI> classIRIs = subjectMap.getClassIRIs();
	if (subject != null)
		for (org.openrdf.model.URI classIRI : classIRIs) {
			Statement st = myFactory.createStatement((Resource) subject, RDF.TYPE,
       				(Value) classIRI);
               //dataset.add(subject, predicate, object);
               dataset.addStatement(st);
               
               statements.add(st);
			
			//dataset.add(subject, RDF.TYPE, classIRI);
		}
	
	return statements;
}
 
Example #7
Source File: RowProcessor.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor
 */
public RowProcessor(){
    super();
    config_replacements = Config.variables;
    subj_templates = new ArrayList<>();
    subj_tokens = new ArrayList<>();
    subj_replacements_pos = new ArrayList<>();

    obj_templates = new ArrayList<>();
    obj_tokens = new ArrayList<>();
    obj_templatesMap = new HashMap<>();
    obj_replacements_pos = new ArrayList<>();

    factory = ValueFactoryImpl.getInstance();
    rml_factory = new ConcreteRMLProcessorFactory();
}
 
Example #8
Source File: RowProcessor.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a RowProcessor by initializing its fields with pre-calculated variables.
 * It is used in order to create a copy of an existing RowProcessor.
 *
 * @param in_headers input headers
 * @param subjTemplates input subject  templates
 * @param subjTokens input subject tokens
 * @param subjReplacements_pos input sublect replacements
 * @param objTemplates input object templates
 * @param objTokens input object tokens
 * @param objReplacements_pos input object replacements
 * @param objTemplatesMap input object templates map
 */
public RowProcessor(Set<String> in_headers, List<String> subjTemplates, List<List<String>> subjTokens
                    ,List<List<String>> subjReplacements_pos, List<String> objTemplates, List<List<String>> objTokens
                    ,List<List<String>> objReplacements_pos,  Map<String, Integer> objTemplatesMap){
    super();
    config_replacements = Config.variables;
    factory = ValueFactoryImpl.getInstance();
    rml_factory = new ConcreteRMLProcessorFactory();

    headers = in_headers;

    subj_templates = subjTemplates;
    subj_tokens = subjTokens;
    subj_replacements_pos = subjReplacements_pos;

    obj_templates = objTemplates;
    obj_tokens = objTokens;
    obj_templatesMap = objTemplatesMap;
    obj_replacements_pos = objReplacements_pos;
}
 
Example #9
Source File: ObjectConstructorMarshall.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public ObjectConstructorMarshall(ValueFactory vf, Class<T> type)
		throws NoSuchMethodException {
	this.vf = vf;
	ValueFactory uf = ValueFactoryImpl.getInstance();
	this.datatype = uf.createURI("java:", type.getName());
	try {
		constructor = type.getConstructor(new Class[] { String.class });
	} catch (NoSuchMethodException e) {
		try {
			constructor = type
					.getConstructor(new Class[] { CharSequence.class });
		} catch (NoSuchMethodException e1) {
			throw e;
		}
	}
}
 
Example #10
Source File: JoinRMLPerformer.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
/**
   * Compare expressions from join to complete it
   * 
   * @param node current object in parent iteration
   * @param dataset
   * @param map 
   */
  @Override
  public Collection<Statement> perform(Object node, SesameDataSet dataset, TriplesMap map) {
  	List<Statement> statements=new LinkedList<>();
  	
      Value object = processor.processSubjectMap(dataset, map.getSubjectMap(), node);

      if (object == null){
          return statements;
      }       
      log.debug("[JoinRMLPerformer:addTriples] Subject "
                  + subject + " Predicate " + predicate + "Object " + object.toString());
      
      //add the join triple
      ValueFactory myFactory = ValueFactoryImpl.getInstance();
Statement st = myFactory.createStatement((Resource) subject, predicate,
		(Value) object);
      //dataset.add(subject, predicate, object);
      dataset.addStatement(st);
      
      statements.add(st);
      return statements;
  }
 
Example #11
Source File: LinkedDataServletTest.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Test
public void delete() throws IOException, CumulusStoreException, ServletException {

	for (int i = 0; i < URIS.size(); i++) {

		/*
		 * prepare mock ...
		 */
		String uri = URIS.get(i);
		when(_request.getRequestURL()).thenReturn(new StringBuffer(uri));

		/*
		 * delete entity
		 */
		_ld_servlet.doDelete(_request, _response);

		/*
		 * verify deletion
		 */
		verify(_response).setStatus(HttpServletResponse.SC_OK);
		assertTrue("entity '" + uri + "' should have been deleted", !TRIPLE_STORE.query(new Value[] { ValueFactoryImpl.getInstance().createURI(uri), null, null })
				.hasNext());
	}
}
 
Example #12
Source File: ValueOfMarshall.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public ValueOfMarshall(ValueFactory vf, Class<T> type)
		throws NoSuchMethodException {
	this.vf = vf;
	ValueFactoryImpl uf = ValueFactoryImpl.getInstance();
	this.datatype = uf.createURI("java:", type.getName());
	try {
		this.valueOfMethod = type.getDeclaredMethod("valueOf",
				new Class[] { String.class });
		if (!Modifier.isStatic(valueOfMethod.getModifiers()))
			throw new NoSuchMethodException("valueOf Method is not static");
		if (!type.equals(valueOfMethod.getReturnType()))
			throw new NoSuchMethodException("Invalid return type");
	} catch (NoSuchMethodException e) {
		try {
			this.valueOfMethod = type.getDeclaredMethod("getInstance",
					new Class[] { String.class });
			if (!Modifier.isStatic(valueOfMethod.getModifiers()))
				throw new NoSuchMethodException(
						"getInstance Method is not static");
			if (!type.equals(valueOfMethod.getReturnType()))
				throw new NoSuchMethodException("Invalid return type");
		} catch (NoSuchMethodException e2) {
			throw e;
		}
	}
}
 
Example #13
Source File: FilterableTripleHandler.java    From anthelion with Apache License 2.0 5 votes vote down vote up
public void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context)
		throws TripleHandlerException {
	// if uri is in negative namespace which has to be filtered out and not
	// in the positive list - return directly
	for (String negativeFilterNamespace : negativeFilterNamespaces) {
		if (p.toString().startsWith(negativeFilterNamespace)) {
			for (String positiveFilterNamespace : positiveFilterNamespaces) {
				if (!p.toString().startsWith(positiveFilterNamespace)) {
					System.out.println(
							"Namespace filtered: " + s.toString() + " , " + p.toString() + ", " + o.toString());
					return;
				}
			}
		}
	}

	// check the css
	for (String negativeFileter : eveilNamespacesCSS)
		if (p.toString().toLowerCase().contains(negativeFileter))
			return;

	URI extractorUri = extractorNames.get(context.getExtractorName());
	if (extractorUri == null) {
		extractorUri = ValueFactoryImpl.getInstance().createURI("ex:" + context.getExtractorName());
		extractorNames.put(context.getExtractorName(), extractorUri);
	}

	try {
		handleStatement(s, p, o, context.getDocumentURI(), extractorUri);
		totalTriples++;
	} catch (RDFHandlerException e) {
		throw new TripleHandlerException("Unable to recieve Triple", e);
	}

	String ex = context.getExtractorName();
	if (triplesPerExtractor.containsKey(ex)) {
		triplesPerExtractor.put(ex, new Long(triplesPerExtractor.get(ex) + 1));
	}
}
 
Example #14
Source File: ObjectRepositoryFactory.java    From anno4j with Apache License 2.0 5 votes vote down vote up
/**
 * Create an uninitialised ObjectRepository without a delegate.
 */
@Override
public ObjectRepository getRepository(RepositoryImplConfig configuration)
		throws RepositoryConfigException {
	if (!(configuration instanceof ObjectRepositoryConfig))
		throw new RepositoryConfigException("Invalid configuration class: "
				+ configuration.getClass());
	ObjectRepositoryConfig config = (ObjectRepositoryConfig) configuration;
	return getRepository(config, ValueFactoryImpl.getInstance());
}
 
Example #15
Source File: AdviceTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void test() throws Exception {
	URI name = ValueFactoryImpl.getInstance().createURI("urn:test:",
			"instance");
	Person person = con.addDesignation(con.getObject(name), Person.class);
	try {
		person.doSomethingImportant();
		fail();
	} catch (ProtectedException e) {
		// success
	}
}
 
Example #16
Source File: RoleMapperTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testMixinClass() throws Exception {
	RoleMapper rm = new RoleMapper();
	ValueFactoryImpl vf = ValueFactoryImpl.getInstance();
	rm.addConcept(MixedClass.class, vf.createURI("urn:MixedClass"));
	Collection<Class<?>> roles = rm.findRoles(vf.createURI("urn:MixedClass"));
	assertTrue(roles.contains(BehaviourClass.class));
}
 
Example #17
Source File: DesignationTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testDesignateEntity() throws Exception {
	URI name = ValueFactoryImpl.getInstance().createURI("urn:resource");
	Resource resource = (Resource) con.getObject(name);
	assertEquals(0, resource.getRdfTypes().size());
	Property prop = con.addDesignation(resource, Property.class);
	assertEquals(1, prop.getRdfTypes().size());
	con.removeDesignation(prop, Property.class);
	resource = (Resource) con.getObject(name);
	assertTrue(!(resource instanceof Property));
	assertEquals(0, resource.getRdfTypes().size());
}
 
Example #18
Source File: Test_Ticket_789.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void populate() throws Exception {
	final ValueFactoryImpl vf = ValueFactoryImpl.getInstance();
	final Statement[] a = new Statement[] {
			vf.createStatement(s, p, o, c),
			vf.createStatement(s, p, o, namedGraph1),
			vf.createStatement(s, p1, o, namedGraph2),
			vf.createStatement(s, p, o, defaultGraph1),
			vf.createStatement(s, p, p, defaultGraph2),
			vf.createStatement(p, p, p, c)
	};

	final AddOp addOp = new AddOp(Arrays.asList(a));

	m_repo.add(addOp);
}
 
Example #19
Source File: MergeTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testComplexMerge() throws Exception {
	URI name = ValueFactoryImpl.getInstance().createURI("urn:test:", "comp");
	con.addDesignation(con.getObject(name), BigCompany.class);
	con.addObject(name, new SmallCompanyImpl(name));
	Company company = (Company) con.getObject(name);
	assertTrue(company instanceof BigCompany);
}
 
Example #20
Source File: RoleMapperTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
	super.setUp();
	vf = ValueFactoryImpl.getInstance();
	ObjectRepositoryFactory factory = new ObjectRepositoryFactory();
	mapper = factory.createRoleMapper(vf);
}
 
Example #21
Source File: RangeQueriesTest.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * A literal cannot be converted in a decimal representation.
 */
@Test
public void boundWithUnconvertibleLiteral() {
	final String[] nAnValues = { null, "", " ", "abc1234def", "ThisIsNaN", };
	for (final String nan : nAnValues) {
		final Literal literal = nan != null ? ValueFactoryImpl.getInstance().createLiteral(nan) : null;
		assertEquals(TripleStore.MAX_UPPER_BOUND, ((TripleStore) _tripleStore).asDecimal(literal, TripleStore.MAX_UPPER_BOUND));
		assertEquals(TripleStore.MIN_LOWER_BOUND, ((TripleStore) _tripleStore).asDecimal(literal, TripleStore.MIN_LOWER_BOUND));
	}
}
 
Example #22
Source File: UserGuideTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testElmoManager2() throws Exception {
	factory = new ObjectRepositoryFactory().createRepository(new ObjectRepositoryConfig(), repository);
	manager = factory.getConnection();

	String ns = NS;
	URI id = ValueFactoryImpl.getInstance().createURI(ns, "E340076");
	Object john = manager.getObject(id);

	assertNotNull(john);
	assertEquals(id, manager.addObject(john));

	// the subject john has the uri of
	// "http://www.example.com/rdf/2007/E340076"
}
 
Example #23
Source File: JoinReferenceRMLPerformer.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
/**
 * Compare expressions from join to complete it
 * 
 * @param node current object in parent iteration
 * @param dataset
 * @param map 
 */
@Override
public Collection<Statement> perform(Object node, SesameDataSet dataset, TriplesMap map) {
	List<Statement> statements=new LinkedList<>();
    //Value object = processor.processSubjectMap(dataset, map.getSubjectMap(), node);
	List<Object> objects = processor.extractValueFromNode(node, expr);
			
    if (objects == null){
        return statements;
    }       
    log.debug("[JoinReferenceRMLPerformer:addTriples] Subject "
                + subject + " Predicate " + predicate + "Object " + objects.toString());
    
    ValueFactory myFactory = ValueFactoryImpl.getInstance();		
    
    //add the join triple
    for(Object obj:objects){
    	Statement st = myFactory.createStatement((Resource) subject, predicate,
				(Value) new LiteralImpl(obj.toString().trim()));
        //dataset.add(subject, predicate, object);
        dataset.addStatement(st);
        
        statements.add(st);
        
    	//dataset.add(subject, predicate, new LiteralImpl(obj.toString().trim()));
    }
    return statements;
}
 
Example #24
Source File: TupleQueryExecutor.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private Map<String, Value> getBindings(Map<String, Object> variables)
{
    Map<String, Value> bindings = new HashMap<>();
    for (Map.Entry<String, Object> stringObjectEntry : variables.entrySet())
    {
        if (!stringObjectEntry.getValue().getClass().equals(Object.class))
            bindings.put(stringObjectEntry.getKey(), ValueFactoryImpl.getInstance().createLiteral(stringObjectEntry.getValue().toString()));
    }
    return bindings;
}
 
Example #25
Source File: DefaultBlueprintsValueFactory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an instance with a simple Sesame ValueFactoryImpl.
 */
public DefaultBlueprintsValueFactory(final String graphNamespace,
        final String vertexNamespace, final String edgeNamespace,
        final URI type, final URI vertex, final URI edge, final URI label) {
    
    this(new ValueFactoryImpl(), graphNamespace, vertexNamespace,
            edgeNamespace, type, vertex, edge, label);
    
}
 
Example #26
Source File: Test_Ticket_605.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A Java version of the scala example.
 * 
 * @throws Exception
 * 
 * @see <a href="http://trac.bigdata.com/ticket/605" > Error in function
 *      :rangeCount </a>
 */
public void test_ticket_605() throws Exception {

   final URI s = new URIImpl(":s");
   final URI p = new URIImpl(":p");
   final URI o = new URIImpl(":o");

   final Statement[] a = new Statement[] { ValueFactoryImpl.getInstance()
         .createStatement(s, p, o) };

   final AddOp addOp = new AddOp(Arrays.asList(a));

   m_repo.add(addOp);

   final TupleQueryResult result = m_repo.prepareTupleQuery(
         "SELECT * {?s ?p ?o} LIMIT 100").evaluate();
   try {
      while (result.hasNext()) {
         final BindingSet bset = result.next();
         if (log.isInfoEnabled()) {
            log.info(bset);
         }
         System.out.println(bset);
      }
   } finally {
      result.close();
   }

}
 
Example #27
Source File: RangeQueriesTest.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * A literal can be converted in a decimal representation.
 */
@Test
public void boundWithConvertibleLiteral() {
	final String[] numericValues = { "1", "0", "1.9927883", "-0.288382", "132" };
	for (final String value : numericValues) {
		assertEquals(new BigDecimal(value), ((TripleStore) _tripleStore).asDecimal(ValueFactoryImpl.getInstance().createLiteral(value), null));
	}
}
 
Example #28
Source File: TestFederatedQuery.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Read the expected graph query result from the specified resource
  * 
  * @param resultFile
  * @return
  * @throws Exception
  */
 private Set<Statement> readExpectedGraphQueryResult(String resultFile) throws Exception
 {
     final RDFFormat rdfFormat = Rio.getParserFormatForFileName(resultFile);
 
     if (rdfFormat != null) {
         final RDFParser parser = Rio.createParser(rdfFormat);
         parser.setDatatypeHandling(DatatypeHandling.IGNORE);
         parser.setPreserveBNodeIDs(true);
         parser.setValueFactory(ValueFactoryImpl.getInstance());
 
         final Set<Statement> result = new LinkedHashSet<Statement>();
         parser.setRDFHandler(new StatementCollector(result));
 
final InputStream in = TestFederatedQuery.class
		.getResourceAsStream(TEST_RESOURCE_PATH + resultFile);
         try {
             parser.parse(in, null);     // TODO check
         }
         finally {
             in.close();
         }
 
         return result;
     }
     else {
         throw new RuntimeException("Unable to determine file type of results file");
     }
 }
 
Example #29
Source File: LinkedDataServlet.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * <p> Deletes all triples associated with the specific entity. That is, an HTTP DELETE request
 * on the URI {@code http://example.org/resource/1} would delete the triples:</p>
 * <br>
 * <p>
 * http://http://example.org/resource/1 ?p ?o . <br>
 * ?s ?p http://http://example.org/resource/1 .
 * </p>
 * 
 */
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

	try {

		final Store store = ((Store) getServletContext().getAttribute(ConfigParams.STORE));

		if ((store == null) || !store.isOpen()) {
			_log.error(MessageCatalog._00025_CUMULUS_SYSTEM_INTERNAL_FAILURE_MSG + " Store was null or not initialized.");
			sendError(
					req,
					resp,
					HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
					MessageCatalog._00025_CUMULUS_SYSTEM_INTERNAL_FAILURE_MSG);
			return;
		}

		final Iterator<Statement> removeIterator = store.describe(ValueFactoryImpl.getInstance().createURI(req.getRequestURL().toString()), false);

		if (removeIterator.hasNext()) {
			store.removeData(removeIterator);
			resp.setStatus(HttpServletResponse.SC_OK);
		} else {
			resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
		}

	} catch (Exception exception) {
		_log.error(MessageCatalog._00025_CUMULUS_SYSTEM_INTERNAL_FAILURE, exception);
		sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, MessageCatalog._00025_CUMULUS_SYSTEM_INTERNAL_FAILURE_MSG, exception);
	}
}
 
Example #30
Source File: RowProcessor.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
/**
 * Calculate the RDF Statements of the input row.
 *
 * @param subject the subject of the Statements, which represents the input Row.
 * @param pom_list list containing all the predicate-object maps
 * @param row input Spark Row.
 * @param map examined TripleMap.
 * @param list_predicates list containing all the predicates.
 * @param index index that indicates the examined TripleMap.
 * @return The Statements produced by the Row.
 */
public Collection<Statement> processPredicateObjectMap(Resource subject, List<PredicateObjectMap> pom_list,
                                                       Row row, TriplesMap map, List<URI> list_predicates, int index) {
    List<Statement> statements = new LinkedList<>();
    ValueFactory myFactory = ValueFactoryImpl.getInstance();

    int predicate_index = 0;

    for (PredicateObjectMap pom : pom_list) {
        // Get predicate
        URI predicate = list_predicates.get(predicate_index);
        predicate_index++;

        //WARNING: I've deleted the join processes

        // process the objectmaps
        Set<ObjectMap> objectMaps = pom.getObjectMaps();
        for (ObjectMap objectMap : objectMaps) {
            Value object = processObjectMap(objectMap, row,
                    map, subject, predicate, index);
            if (object == null) continue;
            if (object.stringValue() != null || !object.stringValue().equals("")) {
                Statement st = myFactory.createStatement((Resource) subject, predicate, (Value) object);
                statements.add(st);
            }
        }
    }
    return statements;
}