예제 #1
1
  @GET
  @Path("join/{spaceName}")
  public Response join(
      @PathParam("spaceName") String spaceName,
      @Context SecurityContext sc,
      @Context UriInfo uriInfo) {

    try {

      String userId = getUserId(sc, uriInfo);
      if (userId == null) {
        return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build();
      }

      SpaceService spaceService =
          (SpaceService)
              ExoContainerContext.getCurrentContainer()
                  .getComponentInstanceOfType(SpaceService.class);
      if (spaceService.getSpaceById(spaceName).getRegistration().equals("open"))
        spaceService.addMember(spaceService.getSpaceById(spaceName), userId);

      return Response.ok("{}", MediaType.APPLICATION_JSON).cacheControl(cacheControl).build();
    } catch (Exception e) {
      log.error("Error in space deny rest service: " + e.getMessage(), e);
      return Response.ok("error").cacheControl(cacheControl).build();
    }
  }
예제 #2
0
  @GET
  @Path("/getcomponents/{orderid}")
  @Produces(MediaType.APPLICATION_JSON)
  public List<OutViewComponent> getComponentsByOrder(@PathParam("orderid") String orderid) {
    List<OutViewComponent> returnValue = new ArrayList<OutViewComponent>();
    try {
      int id = Integer.parseInt(orderid);
      returnValue = DataManager.getInstance().getComponentsForView(id);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    return returnValue;
  }
예제 #3
0
  @GET
  @Path("/gettypes/{groupid}")
  @Produces(MediaType.APPLICATION_JSON)
  public List<String> getTypesByGroup(@PathParam("groupid") String groupid) {
    List<String> returnValue = new ArrayList<String>();
    try {
      for (Types type : DataManager.getInstance().getTypes(groupid)) {
        returnValue.add(type.getCode());
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    return returnValue;
  }
예제 #4
0
  @GET
  @Path("/getgroups/{weightid}")
  @Produces(MediaType.APPLICATION_JSON)
  public List<String> getGroupsByWeight(@PathParam("weightid") String weightid) {
    List<String> returnValue = new ArrayList<String>();
    try {
      for (Groups group : DataManager.getInstance().getGroups(weightid)) {
        returnValue.add(group.getCode());
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    return returnValue;
  }
예제 #5
0
 @DELETE
 @Path("{route_id}")
 @Produces(MediaType.APPLICATION_JSON)
 public String deletePlace(@PathParam("route_id") String routeID) {
   syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
   JSONObject reply = new JSONObject();
   try {
     syncCache.delete(routeID);
     return reply
         .append("status", "OK")
         .append("message", "successfully deleted route " + routeID + " from " + "memcache")
         .toString();
   } catch (Exception e) {
     return new JSONObject().append("status", "fail").append("message", e.getMessage()).toString();
   }
 }
예제 #6
0
  @POST
  @Path("/update")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public Response update(String jsonString) {
    ObjectMapper mapper = new ObjectMapper();
    UpdateResult result = null;
    try {
      result = mapper.readValue(jsonString, UpdateResult.class);
      DAOManager.getInstance().getResultDAO().updateResult(result);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    return Response.status(200).build();
  }
예제 #7
0
  @GET
  @Path("/getresult/{orderid}/{componentid}")
  @Produces(MediaType.APPLICATION_JSON)
  public List<OutViewResult> getResultByOrderComponent(
      @PathParam("orderid") String orderid, @PathParam("componentid") String componentid) {
    List<OutViewResult> returnValue = new ArrayList<OutViewResult>();
    try {
      int ordId = Integer.parseInt(orderid);
      int cmpId = Integer.parseInt(componentid);
      returnValue = DataManager.getInstance().getResultsForView(ordId, cmpId);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    return returnValue;
  }
예제 #8
0
  @GET
  @Path("public")
  public Response getPublicSpaces(@Context SecurityContext sc, @Context UriInfo uriInfo) {

    try {
      String userId = getUserId(sc, uriInfo);
      if (userId == null) {
        return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build();
      }

      SpaceService spaceService =
          (SpaceService)
              ExoContainerContext.getCurrentContainer()
                  .getComponentInstanceOfType(SpaceService.class);
      ListAccess<Space> publicSpaces = spaceService.getPublicSpacesWithListAccess(userId);

      JSONArray jsonArray = new JSONArray();

      Space[] spaces = publicSpaces.load(0, publicSpaces.getSize());
      if (spaces != null && spaces.length > 0) {
        for (Space space : spaces) {

          if (space.getVisibility().equals(Space.HIDDEN)) continue;
          if (space.getRegistration().equals(Space.CLOSE)) continue;

          JSONObject json = new JSONObject();
          json.put("name", space.getName());
          json.put("displayName", space.getDisplayName());
          json.put("spaceId", space.getId());
          jsonArray.put(json);
        }
      }

      return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON)
          .cacheControl(cacheControl)
          .build();
    } catch (Exception e) {
      log.error("Error in space invitation rest service: " + e.getMessage(), e);
      return Response.ok("error").cacheControl(cacheControl).build();
    }
  }
예제 #9
0
  @GET
  @Path("myspaces")
  public Response request(@Context SecurityContext sc, @Context UriInfo uriInfo) {

    try {

      String userId = getUserId(sc, uriInfo);
      if (userId == null) {
        return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build();
      }

      SpaceService spaceService =
          (SpaceService)
              ExoContainerContext.getCurrentContainer()
                  .getComponentInstanceOfType(SpaceService.class);
      List<Space> mySpaces = spaceService.getAccessibleSpaces(userId);

      JSONArray jsonArray = new JSONArray();

      for (Space space : mySpaces) {
        JSONObject json = new JSONObject();
        json.put("name", space.getName());
        json.put("spaceId", space.getId());
        json.put("displayName", space.getDisplayName());
        json.put("spaceUrl", space.getUrl());
        json.put("members", space.getMembers().length);
        jsonArray.put(json);
      }

      return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON)
          .cacheControl(cacheControl)
          .build();

    } catch (Exception e) {
      log.error("Error in space deny rest service: " + e.getMessage(), e);
      return Response.ok("error").cacheControl(cacheControl).build();
    }
  }
예제 #10
0
  @GET
  @Path("suggestions")
  public Response getSuggestions(@Context SecurityContext sc, @Context UriInfo uriInfo) {

    try {

      String userId = getUserId(sc, uriInfo);
      if (userId == null) {
        return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build();
      }

      SpaceService spaceService =
          (SpaceService)
              ExoContainerContext.getCurrentContainer()
                  .getComponentInstanceOfType(SpaceService.class);
      List<Space> suggestedSpaces = spaceService.getPublicSpaces(userId);
      IdentityManager identityManager =
          (IdentityManager)
              ExoContainerContext.getCurrentContainer()
                  .getComponentInstanceOfType(IdentityManager.class);
      Identity identity =
          identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId);
      List<Identity> connections = identityManager.getConnections(identity);

      JSONArray jsonArray = new JSONArray();

      for (Space space : suggestedSpaces) {

        if (space.getVisibility().equals(Space.HIDDEN)) continue;
        if (space.getRegistration().equals(Space.CLOSE)) continue;
        List<Identity> identityListMember = new ArrayList<Identity>();
        String avatar = space.getAvatarUrl();
        if (avatar == null) {
          avatar = "/social-resources/skin/ShareImages/SpaceImages/SpaceLogoDefault_61x61.gif";
        }
        for (String mem : space.getMembers()) {
          Identity identityMem =
              identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, mem);
          identityListMember.add(identityMem);
        }
        int k = 0;
        for (Identity i : identityListMember) {
          for (Identity j : connections) {
            if (j.equals(i)) {
              k++;
            }
          }
        }
        String spaceType = "";
        if (space.getRegistration().equals(Space.OPEN)) {
          spaceType = "Public";
        } else {
          spaceType = "Private";
        }
        JSONObject json = new JSONObject();
        json.put("name", space.getName());
        json.put("spaceId", space.getId());
        json.put("displayName", space.getDisplayName());
        json.put("spaceUrl", space.getUrl());
        json.put("avatarUrl", avatar);
        json.put("registration", space.getRegistration());
        json.put("members", space.getMembers().length);
        json.put("privacy", spaceType);
        json.put("number", k);
        jsonArray.put(json);
      }

      return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON)
          .cacheControl(cacheControl)
          .build();

    } catch (Exception e) {
      log.error("Error in space invitation rest service: " + e.getMessage(), e);
      return Response.ok("error").cacheControl(cacheControl).build();
    }
  }