use of won.protocol.util.NeedModelWrapper in project webofneeds by researchstudio-sat.
the class GoalInstantiationProducer method getNeedContentModelWithoutGoals.
private Model getNeedContentModelWithoutGoals(Dataset need) {
NeedModelWrapper needWrapper = new NeedModelWrapper(need);
Model need1Model = needWrapper.copyNeedModel(NeedGraphType.NEED);
for (Resource goal : needWrapper.getGoals()) {
RdfUtils.removeResource(need1Model, goal);
}
return need1Model;
}
use of won.protocol.util.NeedModelWrapper in project webofneeds by researchstudio-sat.
the class GoalInstantiationProducer method createAllGoalInstantiationResults.
/**
* create all possible goal instantiations between two needs.
* Including the separate goals of each need as well.
*
* @return
*/
public Collection<GoalInstantiationResult> createAllGoalInstantiationResults() {
NeedModelWrapper needWrapper1 = new NeedModelWrapper(need1);
NeedModelWrapper needWrapper2 = new NeedModelWrapper(need2);
Collection<GoalInstantiationResult> results = new LinkedList<>();
boolean addedGoal2s = false;
for (Resource goal1 : needWrapper1.getGoals()) {
results.add(findInstantiationForGoal(goal1));
for (Resource goal2 : needWrapper2.getGoals()) {
GoalInstantiationResult instantiationResult = findInstantiationForGoals(goal1, goal2);
results.add(instantiationResult);
if (!addedGoal2s) {
results.add(findInstantiationForGoal(goal2));
}
}
addedGoal2s = true;
}
if (!addedGoal2s) {
for (Resource goal2 : needWrapper2.getGoals()) {
results.add(findInstantiationForGoal(goal2));
}
}
return results;
}
use of won.protocol.util.NeedModelWrapper in project webofneeds by researchstudio-sat.
the class GoalInstantiationTest method exampleTaxiFakeLocation_validity.
@Test
public void exampleTaxiFakeLocation_validity() throws IOException {
Dataset taxiOffer = loadDataset(baseFolder + "ex7_taxioffer.trig");
Dataset taxiDemand = loadDataset(baseFolder + "ex7_taxi.trig");
GoalInstantiationProducer goalInstantiation = new GoalInstantiationProducer(taxiOffer, taxiDemand, null, "http://example.org/", "http://example.org/blended/");
Collection<GoalInstantiationResult> results = goalInstantiation.createGoalInstantiationResultsForNeed1();
for (GoalInstantiationResult res : results) {
res.getInstanceModel().write(System.out, "TRIG");
Assert.assertTrue(res.isConform());
Coordinate departureAddress = getAddress(loadSparqlQuery("/won/utils/goals/extraction/address/northWestCornerQuery.rq"), res.getInstanceModel());
Coordinate destinationAddress = getAddress(loadSparqlQuery("/won/utils/goals/extraction/address/southEastCornerQuery.rq"), res.getInstanceModel());
Assert.assertEquals(departureAddress, new Coordinate(48.218727f, 16.360141f));
Assert.assertEquals(destinationAddress, new Coordinate(48.218828f, 16.360241f));
}
NeedModelWrapper needWrapper1 = new NeedModelWrapper(taxiOffer);
Resource goal = needWrapper1.getGoals().iterator().next();
GoalInstantiationResult result = goalInstantiation.findInstantiationForGoal(goal);
Assert.assertTrue(result.isConform());
GoalInstantiationResult recheckResultModel = GoalInstantiationProducer.findInstantiationForGoalInDataset(taxiOffer, goal, result.getInstanceModel());
Assert.assertTrue(recheckResultModel.isConform());
}
use of won.protocol.util.NeedModelWrapper in project webofneeds by researchstudio-sat.
the class CreateNeedMessageProcessor method storeNeed.
private Need storeNeed(final WonMessage wonMessage) {
Dataset needContent = wonMessage.getMessageContent();
List<WonMessage.AttachmentHolder> attachmentHolders = wonMessage.getAttachments();
// remove attachment and its signature from the needContent
removeAttachmentsFromNeedContent(needContent, attachmentHolders);
URI needURI = getNeedURIFromWonMessage(needContent);
if (!needURI.equals(wonMessage.getSenderNeedURI()))
throw new IllegalArgumentException("receiverNeedURI and NeedURI of the content are not equal");
Need need = new Need();
need.setState(NeedState.ACTIVE);
need.setNeedURI(needURI);
// ToDo (FS) check if the WON node URI corresponds with the WON node (maybe earlier in the message layer)
NeedEventContainer needEventContainer = needEventContainerRepository.findOneByParentUri(needURI);
if (needEventContainer == null) {
needEventContainer = new NeedEventContainer(need, need.getNeedURI());
} else {
throw new UriAlreadyInUseException("Found a NeedEventContainer for the need we're about to create (" + needURI + ") - aborting");
}
need.setWonNodeURI(wonMessage.getReceiverNodeURI());
ConnectionContainer connectionContainer = new ConnectionContainer(need);
need.setConnectionContainer(connectionContainer);
need.setEventContainer(needEventContainer);
// store the need content
DatasetHolder datasetHolder = new DatasetHolder(needURI, needContent);
// store attachments
List<DatasetHolder> attachments = new ArrayList<>(attachmentHolders.size());
for (WonMessage.AttachmentHolder attachmentHolder : attachmentHolders) {
datasetHolder = new DatasetHolder(attachmentHolder.getDestinationUri(), attachmentHolder.getAttachmentDataset());
attachments.add(datasetHolder);
}
// add everything to the need model class and save it
need.setDatatsetHolder(datasetHolder);
need.setAttachmentDatasetHolders(attachments);
need = needRepository.save(need);
connectionContainerRepository.save(connectionContainer);
NeedModelWrapper needModelWrapper = new NeedModelWrapper(needContent);
Collection<String> facets = needModelWrapper.getFacetUris();
if (facets.size() == 0)
throw new IllegalArgumentException("at least one property won:hasFacet required ");
for (String facetUri : facets) {
// TODO: check if there is a implementation for the facet on the node
Facet f = new Facet();
f.setNeedURI(needURI);
f.setTypeURI(URI.create(facetUri));
facetRepository.save(f);
}
return need;
}
use of won.protocol.util.NeedModelWrapper in project webofneeds by researchstudio-sat.
the class AbstractCreateNeedAction method createWonMessage.
protected WonMessage createWonMessage(WonNodeInformationService wonNodeInformationService, URI needURI, URI wonNodeURI, Dataset needDataset, final boolean usedForTesting, final boolean doNotMatch) throws WonMessageBuilderException {
NeedModelWrapper needModelWrapper = new NeedModelWrapper(needDataset);
if (doNotMatch) {
needModelWrapper.addFlag(WON.NO_HINT_FOR_ME);
needModelWrapper.addFlag(WON.NO_HINT_FOR_COUNTERPART);
}
if (usedForTesting) {
needModelWrapper.addFlag(WON.USED_FOR_TESTING);
}
RdfUtils.replaceBaseURI(needDataset, needURI.toString());
return WonMessageBuilder.setMessagePropertiesForCreate(wonNodeInformationService.generateEventURI(wonNodeURI), needURI, wonNodeURI).addContent(needModelWrapper.copyDataset()).build();
}
Aggregations