use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class NoracleSpaceService method joinSpace.
public void joinSpace(String spaceId, String spaceSecret) throws ServiceInvocationException {
if (spaceId == null || spaceId.isEmpty()) {
throw new InvocationBadArgumentException("No space id given");
} else if (spaceSecret == null || spaceSecret.isEmpty()) {
throw new ServiceAccessDeniedException("No space secret given");
}
try {
UserAgentImpl inviteAgent = this.getInviteAgent(spaceId);
inviteAgent.unlock(spaceSecret);
GroupAgent memberAgent = this.getMemberAgent(spaceId);
memberAgent.unlock(inviteAgent);
memberAgent.addMember(Context.get().getMainAgent());
Context.get().storeAgent(memberAgent);
} catch (AgentAccessDeniedException e) {
throw new ServiceAccessDeniedException("Could not unlock agent", e);
} catch (Exception e) {
throw new ServiceInvocationException("Could not join space", e);
}
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class NoracleSpaceService method getSpace.
@Override
public Space getSpace(String spaceId) throws ServiceInvocationException {
if (spaceId == null || spaceId.isEmpty()) {
throw new InvocationBadArgumentException("No space id given");
}
Envelope env;
try {
env = Context.get().requestEnvelope(getSpaceEnvelopeIdentifier(spaceId));
} catch (EnvelopeAccessDeniedException e) {
throw new ServiceAccessDeniedException("Access Denied", e);
} catch (EnvelopeNotFoundException e) {
throw new ResourceNotFoundException("Space Not Found", e);
} catch (EnvelopeOperationFailedException e) {
throw new InternalServiceException("Could not deserialize space object", e);
}
Space space = (Space) env.getContent();
return space;
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class NoracleSpaceService method createSpace.
@Override
public Space createSpace(String name) throws ServiceInvocationException {
Agent mainAgent = Context.get().getMainAgent();
if (mainAgent instanceof AnonymousAgent) {
throw new ServiceNotAuthorizedException("You have to be logged in to create a space");
}
String spaceId = buildSpaceId();
String spaceSecret = generateSpaceSecret();
SpaceInviteAgent spaceInviteAgent;
try {
spaceInviteAgent = new SpaceInviteAgent(spaceSecret);
spaceInviteAgent.unlock(spaceSecret);
Context.get().storeAgent(spaceInviteAgent);
} catch (AgentOperationFailedException | CryptoException e) {
throw new InternalServiceException("Could not create space invite agent", e);
} catch (AgentAccessDeniedException | AgentAlreadyExistsException | AgentLockedException e) {
throw new InternalServiceException("Could not store space invite agent", e);
}
try {
Envelope envInviteMapping = Context.get().createEnvelope(getInviteMappingIdentifier(spaceId));
envInviteMapping.setPublic();
envInviteMapping.setContent(spaceInviteAgent.getIdentifier());
Context.get().storeEnvelope(envInviteMapping);
} catch (EnvelopeOperationFailedException | EnvelopeAccessDeniedException e) {
throw new InternalServiceException("Could not store space invite mapping", e);
}
GroupAgentImpl spaceMemberGroupAgent;
try {
spaceMemberGroupAgent = GroupAgentImpl.createGroupAgent(new Agent[] { spaceInviteAgent, mainAgent });
spaceMemberGroupAgent.unlock(mainAgent);
Context.get().storeAgent(spaceMemberGroupAgent);
} catch (AgentOperationFailedException | CryptoException | SerializationException e) {
throw new InternalServiceException("Could not create space member group agent", e);
} catch (AgentAccessDeniedException | AgentAlreadyExistsException | AgentLockedException e) {
throw new InternalServiceException("Could not store space member group agent", e);
}
try {
Envelope envGroupMapping = Context.get().createEnvelope(getMemberMappingIdentifier(spaceId));
envGroupMapping.setPublic();
envGroupMapping.setContent(spaceMemberGroupAgent.getIdentifier());
Context.get().storeEnvelope(envGroupMapping);
} catch (EnvelopeOperationFailedException | EnvelopeAccessDeniedException e) {
throw new InternalServiceException("Could not store space group member mapping", e);
}
Envelope env;
try {
env = Context.get().createEnvelope(getSpaceEnvelopeIdentifier(spaceId), mainAgent);
} catch (EnvelopeOperationFailedException | EnvelopeAccessDeniedException e) {
throw new InternalServiceException("Could not create envelope for space", e);
}
env.addReader(spaceMemberGroupAgent);
Space space = new Space(spaceId, spaceSecret, name, mainAgent.getIdentifier(), spaceMemberGroupAgent.getIdentifier());
env.setContent(space);
try {
Context.get().storeEnvelope(env, mainAgent);
} catch (EnvelopeAccessDeniedException | EnvelopeOperationFailedException e) {
throw new InternalServiceException("Could not store space envelope", e);
}
return space;
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class QuestionRelationsResource method changeQuestionRelation.
@PUT
@Path("/{relationId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Changes a question relation", response = QuestionRelation.class), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "No relation id given", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access Denied", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Relation Not Found", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Server Error", response = ExceptionEntity.class) })
public QuestionRelation changeQuestionRelation(@PathParam("relationId") String relationId, @ApiParam(required = true) ChangeQuestionRelationPojo changeQuestionRelationPojo) throws ServiceInvocationException {
Gson gson = new Gson();
String changeRelationPojoJson = gson.toJson(changeQuestionRelationPojo);
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
try {
JSONObject obj = (JSONObject) p.parse(changeRelationPojoJson);
obj.put("relId", relationId);
obj.put("uid", Context.getCurrent().getMainAgent().getIdentifier());
Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_MESSAGE_4, obj.toJSONString());
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Try to log training data
try {
String from = getQuestionText(changeQuestionRelationPojo.getQuestionId1());
String to = getQuestionText(changeQuestionRelationPojo.getQuestionId2());
JSONObject trainingData = new JSONObject();
trainingData.put("from", from);
trainingData.put("to", to);
if (changeQuestionRelationPojo.getDirected())
Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_MESSAGE_42, trainingData.toString());
else
Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_MESSAGE_43, trainingData.toString());
} catch (ServiceInvocationException e) {
/* getDirected will return null at this point */
// Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_ERROR_42,
// changeQuestionRelationPojo.getDirected().toString());
}
return changeQuestionRelation(relationId, changeQuestionRelationPojo.getName(), changeQuestionRelationPojo.getQuestionId1(), changeQuestionRelationPojo.getQuestionId2(), changeQuestionRelationPojo.getDirected());
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class QuestionRelationsResource method getQuestionText.
private String getQuestionText(String questionId) throws ServiceInvocationException {
String qText = "";
Serializable rmiResult = Context.get().invoke(new ServiceNameVersion(NoracleQuestionService.class.getCanonicalName(), NoracleService.API_VERSION), "getQuestion", questionId);
if (rmiResult instanceof Question)
qText = ((Question) rmiResult).getText();
return qText;
}
Aggregations