use of won.protocol.message.processor.exception.UriAlreadyInUseException 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.message.processor.exception.UriAlreadyInUseException in project webofneeds by researchstudio-sat.
the class UriAlreadyUsedCheckingWonMessageProcessor method checkNeedURI.
private void checkNeedURI(final WonMessage message) {
if (message.getMessageType() == WonMessageType.CREATE_NEED) {
URI needURI = WonRdfUtils.NeedUtils.getNeedURI(message.getCompleteDataset());
Need need = needRepository.findOneByNeedURI(needURI);
if (need == null) {
return;
} else {
throw new UriAlreadyInUseException(message.getSenderNeedURI().toString());
}
}
return;
}
Aggregations