use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class SpacesResource method createSpace.
@Override
public Space createSpace(String name) throws ServiceInvocationException {
Serializable rmiResult = Context.get().invoke(new ServiceNameVersion(NoracleSpaceService.class.getCanonicalName(), NoracleService.API_VERSION), "createSpace", name);
Space space;
if (rmiResult instanceof Space) {
space = (Space) rmiResult;
} else {
throw new InternalServiceException("Unexpected result (" + rmiResult.getClass().getCanonicalName() + ") of RMI call");
}
return space;
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class SpacesResource method createSpace.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_HTML)
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "Space successfully created"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "You have to be logged in to create a space", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Server Error", response = ExceptionEntity.class) })
public Response createSpace(@ApiParam(required = true) CreateSpacePojo createSpacePojo) throws ServiceInvocationException {
Space space = createSpace(createSpacePojo.getName());
try {
Gson gson = new Gson();
String spaceJSON = gson.toJson(createSpacePojo);
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
try {
JSONObject obj = (JSONObject) p.parse(spaceJSON);
obj.put("uid", Context.getCurrent().getMainAgent().getIdentifier());
Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_MESSAGE_9, obj.toJSONString());
} catch (ParseException e) {
logger.warning("Problems with monitoring event...");
e.printStackTrace();
}
try {
SpaceSubscription rmiResult = (SpaceSubscription) Context.get().invoke(new ServiceNameVersion(NoracleAgentService.class.getCanonicalName(), NoracleService.API_VERSION), "subscribeToSpace", space.getSpaceId(), space.getSpaceSecret());
} catch (Exception ex) {
logger.warning("Error, while trying to subscribe to space: " + ex.getMessage());
}
// TODO: return https instead of http
URI uri = new URI(null, null, RESOURCE_NAME + "/" + space.getSpaceId(), null);
Response response = Response.created(uri).build();
return response;
} catch (URISyntaxException e) {
logger.warning("URISyntaxException: " + e.getMessage());
throw new InternalServerErrorException(e);
}
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class NoracleAgentService method updateSpaceSubscription.
@Override
public SpaceSubscription updateSpaceSubscription(String agentId, String spaceId, String[] selectedQuestions) throws ServiceInvocationException {
Agent mainAgent = Context.get().getMainAgent();
String envIdentifier = buildSubscriptionId(agentId);
try {
Envelope env = Context.get().requestEnvelope(envIdentifier);
SpaceSubscriptionList spaceSubscriptionList = (SpaceSubscriptionList) env.getContent();
for (SpaceSubscription spaceSubscription : spaceSubscriptionList) {
if (spaceSubscription.getSpaceId().equals(spaceId)) {
spaceSubscription.setSelectedQuestionIds(selectedQuestions);
env.setContent(spaceSubscriptionList);
try {
Context.get().storeEnvelope(env, mainAgent);
} catch (EnvelopeAccessDeniedException e) {
throw new ServiceAccessDeniedException("Envelope Access Denied");
} catch (EnvelopeOperationFailedException e) {
throw new InternalServiceException("Could not store space subscription envelope", e);
}
return spaceSubscription;
}
}
throw new ResourceNotFoundException("Space subscription not found");
} catch (EnvelopeAccessDeniedException e) {
throw new ServiceAccessDeniedException("Envelope Access Denied");
} catch (EnvelopeOperationFailedException e) {
throw new InternalServiceException("Could not fetch space subscription envelope", e);
} catch (EnvelopeNotFoundException e) {
throw new ResourceNotFoundException("No space subscriptions found");
}
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class NoracleAgentService method subscribeToSpace.
@Override
public SpaceSubscription subscribeToSpace(String spaceId, String spaceSecret) throws ServiceInvocationException {
Agent mainAgent = Context.get().getMainAgent();
if (spaceId == null || spaceId.isEmpty()) {
throw new InvocationBadArgumentException("No space id given");
} else if (mainAgent instanceof AnonymousAgent) {
throw new ServiceAccessDeniedException("You have to be logged in to subscribe to a space");
}
Context.get().invoke(new ServiceNameVersion(NoracleSpaceService.class.getCanonicalName(), NoracleService.API_VERSION), "joinSpace", spaceId, spaceSecret);
SpaceSubscription subscription = new SpaceSubscription(spaceId, spaceSecret);
String envIdentifier = buildSubscriptionId(mainAgent.getIdentifier());
Envelope env;
SpaceSubscriptionList subscriptionList;
try {
try {
env = Context.get().requestEnvelope(envIdentifier);
subscriptionList = (SpaceSubscriptionList) env.getContent();
} catch (EnvelopeNotFoundException e) {
env = Context.get().createEnvelope(envIdentifier);
subscriptionList = new SpaceSubscriptionList();
}
} catch (EnvelopeAccessDeniedException e) {
throw new ServiceAccessDeniedException("Envelope Access Denied");
} catch (EnvelopeOperationFailedException e) {
throw new InternalServiceException("Could not create envelope for space subscription", e);
}
subscriptionList.add(subscription);
env.setContent(subscriptionList);
try {
Context.get().storeEnvelope(env, mainAgent);
} catch (EnvelopeAccessDeniedException e) {
throw new ServiceAccessDeniedException("Envelope Access Denied");
} catch (EnvelopeOperationFailedException e) {
throw new InternalServiceException("Could not store space subscription envelope", e);
}
return subscription;
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class NoracleAgentService method updateAgentProfile.
@Override
public NoracleAgentProfile updateAgentProfile(String agentName) throws ServiceInvocationException {
Agent mainAgent = Context.get().getMainAgent();
String envIdentifier = buildAgentProfileId(mainAgent.getIdentifier());
Envelope env;
NoracleAgentProfile profile;
// look for existing profile, otherwise create one
try {
try {
env = Context.get().requestEnvelope(envIdentifier);
profile = (NoracleAgentProfile) env.getContent();
} catch (EnvelopeNotFoundException e) {
env = Context.get().createEnvelope(envIdentifier);
profile = new NoracleAgentProfile();
}
} catch (EnvelopeAccessDeniedException e) {
throw new ServiceAccessDeniedException("Envelope access denied");
} catch (EnvelopeOperationFailedException e) {
throw new InternalServiceException("Could not create new envelope for noracle agent profile", e);
}
profile.setName(agentName);
env.setContent(profile);
env.setPublic();
try {
Context.get().storeEnvelope(env, mainAgent);
} catch (EnvelopeAccessDeniedException e) {
throw new ServiceAccessDeniedException("Envelope access denied");
} catch (EnvelopeOperationFailedException e) {
throw new InternalServiceException("Storing envelope with noracle agent profile failed", e);
}
return profile;
}
Aggregations