use of i5.las2peer.api.persistency.Envelope in project Distributed-Noracle-Backend by Distributed-Noracle.
the class NoracleQuestionRelationService method getQuestionRelation.
@Override
public QuestionRelation getQuestionRelation(String relationId) throws ServiceInvocationException {
if (relationId == null || relationId.isEmpty()) {
throw new InvocationBadArgumentException("No relation id given");
}
Envelope env;
try {
env = Context.get().requestEnvelope(getQuestionRelationEnvelopeIdentifier(relationId));
} catch (EnvelopeAccessDeniedException e) {
throw new ServiceAccessDeniedException("Envelope Access Denied");
} catch (EnvelopeOperationFailedException e) {
throw new InternalServiceException("Could not fetch relation envelope", e);
} catch (EnvelopeNotFoundException e) {
throw new ResourceNotFoundException("Relation Not Found");
}
QuestionRelation relation = (QuestionRelation) env.getContent();
return relation;
}
use of i5.las2peer.api.persistency.Envelope in project Distributed-Noracle-Backend by Distributed-Noracle.
the class NoracleQuestionRelationService method linkQuestionRelationToSpace.
public boolean linkQuestionRelationToSpace(String spaceId, String relationId) {
int relationNumber;
for (relationNumber = 1; relationNumber < MAX_RELATIONS_PER_SPACE; relationNumber++) {
try {
Context.get().requestEnvelope(buildSpaceQuestionRelationNumberId(spaceId, relationNumber));
} catch (EnvelopeNotFoundException e) {
// found free question number
break;
} catch (Exception e) {
// XXX logging
}
}
try {
Envelope spaceQuestionRelationEnv = Context.get().createEnvelope(buildSpaceQuestionRelationNumberId(spaceId, relationNumber));
spaceQuestionRelationEnv.setPublic();
spaceQuestionRelationEnv.setContent(relationId);
Context.get().storeEnvelope(spaceQuestionRelationEnv);
return true;
} catch (EnvelopeOperationFailedException | EnvelopeAccessDeniedException e) {
// TODO exception handling
e.printStackTrace();
}
return false;
}
use of i5.las2peer.api.persistency.Envelope in project Distributed-Noracle-Backend by Distributed-Noracle.
the class NoracleVoteService method getAgentVote.
@Override
public Vote getAgentVote(String objectId, String agentId) throws ServiceInvocationException {
String persEnvId = getAgentVoteEnvelopeIdentifier(agentId, objectId);
try {
Envelope persEnv = Context.get().requestEnvelope(persEnvId);
VoteEntry voteEntry = (VoteEntry) persEnv.getContent();
return voteEntry.getVote();
} catch (EnvelopeAccessDeniedException e) {
throw new InternalServiceException("Someone hijacked your vote envelope", e);
} catch (EnvelopeNotFoundException e) {
return new Vote(0, agentId);
} catch (EnvelopeOperationFailedException e) {
throw new InternalServiceException("Retrieving vote failed", e);
}
}
Aggregations