use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class OwnerProtocolCommunicationServiceImpl method getWonNodeUriWithConnectionUri.
@Override
public synchronized URI getWonNodeUriWithConnectionUri(URI connectionUri) throws NoSuchConnectionException {
// TODO: make this more efficient
Connection con = DataAccessUtils.loadConnection(connectionRepository, connectionUri);
URI needURI = con.getNeedURI();
Need need = needRepository.findByNeedURI(needURI).get(0);
return need.getWonNodeURI();
}
use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class ActivateNeedMessageProcessor method process.
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
URI receiverNeedURI = wonMessage.getReceiverNeedURI();
logger.debug("ACTIVATING need. needURI:{}", receiverNeedURI);
if (receiverNeedURI == null)
throw new IllegalArgumentException("receiverNeedURI is not set");
Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI);
need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI()));
need.setState(NeedState.ACTIVE);
logger.debug("Setting Need State: " + need.getState());
needRepository.save(need);
}
use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class CommentFacet method removeDataManagedByFacet.
private void removeDataManagedByFacet(final Connection con) {
Need need = needRepository.findOneByNeedURI(con.getNeedURI());
Dataset needContent = need.getDatatsetHolder().getDataset();
removeFacetManagedGraph(con.getNeedURI(), needContent);
need.getDatatsetHolder().setDataset(needContent);
needRepository.save(need);
}
use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method getNeedDataset.
@Transactional
public DataWithEtag<Dataset> getNeedDataset(final URI needUri, String etag) {
DataWithEtag<Need> data = null;
try {
data = needInformationService.readNeed(needUri, etag);
} catch (NoSuchNeedException e) {
return DataWithEtag.dataNotFound();
}
if (data.isNotFound()) {
return DataWithEtag.dataNotFound();
}
if (!data.isChanged()) {
return DataWithEtag.dataNotChanged(data);
}
Need need = data.getData();
String newEtag = data.getEtag();
// load the dataset from storage
Dataset dataset = need.getDatatsetHolder().getDataset();
Model metaModel = needModelMapper.toModel(need);
Resource needResource = metaModel.getResource(needUri.toString());
// add connections
Resource connectionsContainer = metaModel.createResource(need.getNeedURI().toString() + "/connections");
metaModel.add(metaModel.createStatement(needResource, WON.HAS_CONNECTIONS, connectionsContainer));
// add need event container
Resource needEventContainer = metaModel.createResource(need.getNeedURI().toString() + "#events", WON.EVENT_CONTAINER);
metaModel.add(metaModel.createStatement(needResource, WON.HAS_EVENT_CONTAINER, needEventContainer));
// add need event URIs
Collection<MessageEventPlaceholder> messageEvents = need.getEventContainer().getEvents();
for (MessageEventPlaceholder messageEvent : messageEvents) {
metaModel.add(metaModel.createStatement(needEventContainer, RDFS.member, metaModel.getResource(messageEvent.getMessageURI().toString())));
}
// add WON node link
needResource.addProperty(WON.HAS_WON_NODE, metaModel.createResource(this.resourceURIPrefix));
// add meta model to dataset
String needMetaInformationURI = uriService.createNeedSysInfoGraphURI(needUri).toString();
dataset.addNamedModel(needMetaInformationURI, metaModel);
addBaseUriAndDefaultPrefixes(dataset);
return new DataWithEtag<>(dataset, newEtag, etag);
}
use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class AbstractCamelProcessor method sendMessageToOwner.
protected void sendMessageToOwner(WonMessage message, URI needURI, String fallbackOwnerApplicationId) {
Need need = needRepository.findOneByNeedURI(needURI);
List<OwnerApplication> ownerApplications = need != null ? need.getAuthorizedApplications() : Collections.EMPTY_LIST;
List<String> ownerApplicationIds = toStringIds(ownerApplications);
// if no owner application ids are authorized, we use the fallback specified (if any)
if (ownerApplicationIds.isEmpty() && fallbackOwnerApplicationId != null) {
ownerApplicationIds.add(fallbackOwnerApplicationId);
}
Map headerMap = new HashMap<String, Object>();
headerMap.put(WonCamelConstants.OWNER_APPLICATIONS, ownerApplicationIds);
messagingService.sendInOnlyMessage(null, headerMap, RdfUtils.writeDatasetToString(message.getCompleteDataset(), WonCamelConstants.RDF_LANGUAGE_FOR_MESSAGE), "seda:OwnerProtocolOut");
}
Aggregations