use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method getNeedDataset.
@Override
@Transactional
public Dataset getNeedDataset(final URI needUri, boolean deep, Integer deepLayerSize) throws NoSuchNeedException, NoSuchConnectionException, NoSuchMessageException {
Dataset dataset = getNeedDataset(needUri, null).getData();
if (deep) {
Need need = needInformationService.readNeed(needUri);
if (need.getState() == NeedState.ACTIVE) {
// only add deep data if need is active
Slice<URI> slice = needInformationService.listConnectionURIs(needUri, 1, deepLayerSize, null, null);
NeedInformationService.PagedResource<Dataset, URI> connectionsResource = toContainerPage(this.uriService.createConnectionsURIForNeed(needUri).toString(), slice);
addDeepConnectionData(connectionsResource.getContent(), slice.getContent());
RdfUtils.addDatasetToDataset(dataset, connectionsResource.getContent());
for (URI connectionUri : slice.getContent()) {
NeedInformationService.PagedResource<Dataset, URI> eventsResource = listConnectionEventURIs(connectionUri, 1, deepLayerSize, null, true);
RdfUtils.addDatasetToDataset(dataset, eventsResource.getContent());
}
}
}
return dataset;
}
use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class CommentFacet method addDataManagedByFacet.
private void addDataManagedByFacet(final Connection con) {
Need need = needRepository.findOneByNeedURI(con.getNeedURI());
Dataset needContent = need.getDatatsetHolder().getDataset();
Model facetManagedGraph = getFacetManagedGraph(con.getNeedURI(), needContent);
List<URI> properties = new ArrayList<>();
PrefixMapping prefixMapping = PrefixMapping.Factory.create();
// prefixMapping.setNsPrefix(SIOC.getURI(),"sioc");
facetManagedGraph.withDefaultMappings(prefixMapping);
facetManagedGraph.setNsPrefix("sioc", SIOC.getURI());
Resource post = facetManagedGraph.createResource(con.getNeedURI().toString(), SIOC.POST);
Resource reply = facetManagedGraph.createResource(con.getRemoteNeedURI().toString(), SIOC.POST);
facetManagedGraph.add(facetManagedGraph.createStatement(facetManagedGraph.getResource(con.getNeedURI().toString()), SIOC.HAS_REPLY, facetManagedGraph.getResource(con.getRemoteNeedURI().toString())));
// add WON node link
logger.debug("linked data:" + RdfUtils.toString(facetManagedGraph));
need.getDatatsetHolder().setDataset(needContent);
needRepository.save(need);
}
use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class NeedManagementService method sendTextMessageToOwner.
public void sendTextMessageToOwner(URI needURI, String message) {
if (needURI == null) {
logger.warn("sendTextMessageToOwner called but needUri is null - doing nothing");
return;
}
if (message == null || message.trim().length() == 0) {
logger.warn("sendTextMessageToOwner called for need {}, but message is null or empty - doing nothing");
return;
}
logger.debug("Sending FromSystem text message to need {}", needURI);
// check if we have that need (e.g. it's not a need living on another node, or does not exist at all)
Need need = needRepository.findOneByNeedURI(needURI);
if (need == null) {
logger.debug("deactivateNeed called for need {} but that need was not found in the repository - doing nothing");
return;
}
URI wonNodeURI = wonNodeInformationService.getWonNodeUri(needURI);
if (wonNodeURI == null) {
logger.debug("deactivateNeed called for need {} but we could not find a WonNodeURI for that need - doing nothing");
return;
}
URI messageURI = wonNodeInformationService.generateEventURI(wonNodeURI);
WonMessageBuilder builder = WonMessageBuilder.setMessagePropertiesForNeedMessageFromSystem(messageURI, needURI, wonNodeURI);
builder.setTextMessage(message);
sendSystemMessage(builder.build());
}
use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class DeactivateNeedMessageFromOwnerReactionProcessor method process.
public void process(final Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
URI receiverNeedURI = wonMessage.getReceiverNeedURI();
logger.debug("DEACTIVATING need. needURI:{}", receiverNeedURI);
if (receiverNeedURI == null)
throw new WonMessageProcessingException("receiverNeedURI is not set");
Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI);
matcherProtocolMatcherClient.needDeactivated(need.getNeedURI(), wonMessage);
// close all connections
Collection<Connection> conns = connectionRepository.getConnectionsByNeedURIAndNotInStateForUpdate(need.getNeedURI(), ConnectionState.CLOSED);
for (Connection con : conns) {
closeConnection(need, con);
}
}
use of won.protocol.model.Need in project webofneeds by researchstudio-sat.
the class DeactivateNeedMessageProcessor method process.
public void process(final Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
URI receiverNeedURI = wonMessage.getReceiverNeedURI();
logger.debug("DEACTIVATING need. needURI:{}", receiverNeedURI);
if (receiverNeedURI == null)
throw new WonMessageProcessingException("receiverNeedURI is not set");
Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI);
need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI()));
need.setState(NeedState.INACTIVE);
need = needRepository.save(need);
}
Aggregations