@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FactoryResource findResource(String path) throws FactoryException { logIt("findResource(...) called"); logIt("params : path=" + path); try { FactoryResourceIdentifier identifier = binding.lookup(path); if (!identifier.getService().equals(SERVICE_NAME)) { throw new CoreServiceException( "Resource " + identifier + " is not managed by " + SERVICE_NAME); } if (identifier.getType().equals(Forum.RESOURCE_NAME)) { return readForum(path); } else if (identifier.getType().equals(ThreadMessage.RESOURCE_NAME)) { return readThreadMessage(path); } throw new CoreServiceException( "Resource " + identifier + " is not managed by " + SERVICE_NAME); } catch (Exception e) { logger.error("unable to find the resource at path " + path, e); throw new CoreServiceException("unable to find the resource at path " + path, e); } }
/** * @param path the location of the project * @return a Project entity */ @TransactionAttribute(TransactionAttributeType.SUPPORTS) public Project getProject(String path) throws ProjectException { try { String caller = membership.getProfilePathForConnectedIdentifier(); pep.checkSecurity(caller, path, "read"); FactoryResourceIdentifier identifier = binding.lookup(path); checkResourceType(identifier, Project.RESOURCE_NAME); Project project = em.find(Project.class, identifier.getId()); if (project == null) { throw new ProjectException("unable to find a project for id " + identifier.getId()); } project.setResourcePath(path); notification.throwEvent( new Event( path, caller, ProjectService.SERVICE_NAME, Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "read"), "")); return project; } catch (Exception e) { throw new ProjectException(e); } }
/** @param path location of the project in the resource tree */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteProject(String path) throws ProjectException { try { String caller = membership.getProfilePathForConnectedIdentifier(); pep.checkSecurity(caller, path, "delete"); FactoryResourceIdentifier identifier = binding.lookup(path); checkResourceType(identifier, Project.RESOURCE_NAME); Project project = em.find(Project.class, identifier.getId()); if (project == null) { throw new ProjectException("unable to find a project for id " + identifier.getId()); } em.remove(project); String policyId = binding.getProperty(path, FactoryResourceProperty.POLICY_ID, false); pap.deletePolicy(policyId); binding.unbind(path); notification.throwEvent( new Event( path, membership.getProfilePathForConnectedIdentifier(), ProjectService.SERVICE_NAME, Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "delete"), "")); } catch (Exception e) { ctx.setRollbackOnly(); throw new ProjectException("unable to delete the project at path " + path); } }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteThreadMessage(String path) throws ForumServiceException { logIt("deleteThreadMessage(...) called"); logger.debug("params : path=" + path); try { // Security check String caller = membership.getProfilePathForConnectedIdentifier(); if (caller == null) { throw new ForumServiceException("Could not get connected profile"); } logIt("caller: " + caller); pep.checkSecurity(caller, path, "delete"); // Look up given path and check resource type FactoryResourceIdentifier identifier = binding.lookup(path); checkResourceType(identifier, ThreadMessage.RESOURCE_NAME); // Find the entity ThreadMessage msg = em.find(ThreadMessage.class, identifier.getId()); if (msg == null) { throw new ForumServiceException("unable to find a msg for id " + identifier.getId()); } if (!browser.hasChildren(path)) { HashMap<String, String> values = forumWS.deleteThreadMessage(msg.getId()); if (values != null && !values.isEmpty()) { String code = (String) values.get("statusCode"); String msgTxt = (String) values.get("statusMessage"); logIt("Message Code:" + code + " Message: " + msgTxt); if (!code.equals(CollaborationUtils.SUCCESS_CODE)) { throw new ForumServiceException( "Error code recieved from the WS." + " Code" + code + " Message:" + msgTxt); } em.remove(msg); // Delete the policy and unbind the resource from this path String policyId = binding.getProperty(path, FactoryResourceProperty.POLICY_ID, false); pap.deletePolicy(policyId); binding.unbind(path); // notify notification.throwEvent( new Event( path, caller, ThreadMessage.RESOURCE_NAME, Event.buildEventType( ForumService.SERVICE_NAME, ThreadMessage.RESOURCE_NAME, "delete"), "")); } else { throw new ForumServiceException("No valid answer from the WS.Check logs."); } } else { throw new ForumServiceException("Thread message has children and cannot be deleted."); } } catch (Exception e) { // ctx.setRollbackOnly(); logger.error("Unable to delete the message at path " + path, e); throw new ForumServiceException("Unable to delete the message at path " + path, e); } }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void updateForum(String path, String name, String date) throws ForumServiceException { logger.debug("Update forum " + path); try { // Check name if (name == null || name == "") { throw new ForumServiceException("Forum name is mandatory."); } // Security check String caller = membership.getProfilePathForConnectedIdentifier(); if (caller == null) { throw new ForumServiceException("Could not get connected profile"); } logIt("caller: " + caller); pep.checkSecurity(caller, path, "update"); // Look up given path and check resource type FactoryResourceIdentifier identifier = binding.lookup(path); checkResourceType(identifier, Forum.RESOURCE_NAME); // Find the entity Forum forum = em.find(Forum.class, identifier.getId()); if (forum == null) { throw new ForumServiceException("Unable to find a forum for id " + identifier.getId()); } HashMap<String, String> values = forumWS.updateForum(forum.getId(), name, date); if (values != null && !values.isEmpty()) { String code = (String) values.get("statusCode"); String msg = (String) values.get("statusMessage"); logIt("Message Code:" + code + " Message: " + msg); if (!code.equals(CollaborationUtils.SUCCESS_CODE)) { throw new ForumServiceException( "Error code recieved from the WS." + " Code" + code + " Message:" + msg); } // Update the entity forum.setName(name); forum.setDate(date); forum.setResourcePath(path); em.merge(forum); binding.setProperty( path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + ""); // notify notification.throwEvent( new Event( path, caller, Forum.RESOURCE_NAME, Event.buildEventType(ForumService.SERVICE_NAME, Forum.RESOURCE_NAME, "update"), "")); logIt(forum.toString()); } else { throw new ForumServiceException("Error in recieving extra details from WS."); } } catch (Exception e) { // ctx.setRollbackOnly(); logger.error("Unable to update the forum at path " + path, e); throw new ForumServiceException("Unable to update the forum at path " + path, e); } }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteName(String path) throws GreetingServiceException { logger.info("deleteName(...) called"); logger.debug("params : path=" + path); try { // Checking if the connected user has the permission to delete the resource giving pep : String caller = membership.getProfilePathForConnectedIdentifier(); pep.checkSecurity(caller, path, "delete"); // Performing a lookup in the naming to recover the Resource Identifier FactoryResourceIdentifier identifier = binding.lookup(path); // Checking if this resource identifier is really a resource managed by this service (a Hello // resource) checkResourceType(identifier, Name.RESOURCE_NAME); // STARTING SPECIFIC EXTERNAL SERVICE RESOURCE LOADING OR METHOD CALLS Name name = em.find(Name.class, identifier.getId()); if (name == null) { throw new GreetingServiceException("unable to find a name for id " + identifier.getId()); } em.remove(name); // END OF EXTERNAL SERVICE INVOCATION // Removing the security policy of this node : String policyId = binding.getProperty(path, FactoryResourceProperty.POLICY_ID, false); pap.deletePolicy(policyId); // Unbinding the resource from this path : binding.unbind(path); // Using the notification service to throw an event : notification.throwEvent( new Event( path, caller, Name.RESOURCE_NAME, Event.buildEventType(GreetingService.SERVICE_NAME, Name.RESOURCE_NAME, "delete"), "")); // Using the indexing service to unindex the name indexing.remove(getServiceName(), path); } catch (Exception e) { // ctx.setRollbackOnly(); logger.error("unable to delete the name at path " + path, e); throw new GreetingServiceException("unable to delete the name at path " + path, e); } }
private void checkResourceType(FactoryResourceIdentifier identifier, String resourceType) throws MembershipServiceException { if (!identifier.getService().equals(getServiceName())) { throw new MembershipServiceException( "resource identifier " + identifier + " does not refer to service " + getServiceName()); } if (!identifier.getType().equals(resourceType)) { throw new MembershipServiceException( "resource identifier " + identifier + " does not refer to a resource of type " + resourceType); } }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void updateName(String path, String value) throws GreetingServiceException { logger.info("updateName(...) called"); logger.debug("params : path=" + path + ", value=" + value); try { // Checking if the connected user has the permission to update the resource giving pep : String caller = membership.getProfilePathForConnectedIdentifier(); pep.checkSecurity(caller, path, "update"); // Performing a lookup in the naming to recover the Resource Identifier FactoryResourceIdentifier identifier = binding.lookup(path); // Checking if this resource identifier is really a resource managed by this service (a Hello // resource) checkResourceType(identifier, Name.RESOURCE_NAME); // STARTING SPECIFIC EXTERNAL SERVICE RESOURCE LOADING OR METHOD CALLS Name name = em.find(Name.class, identifier.getId()); if (name == null) { throw new GreetingServiceException("unable to find a name for id " + identifier.getId()); } name.setValue(value); em.merge(name); // END OF EXTERNAL SERVICE INVOCATION // Need to set some properties on the node : binding.setProperty( path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + ""); // Using the notification service to throw an event : notification.throwEvent( new Event( path, caller, Name.RESOURCE_NAME, Event.buildEventType(GreetingService.SERVICE_NAME, Name.RESOURCE_NAME, "update"), "")); // Using the indexing service to reindex the name newly updated indexing.reindex(getServiceName(), path); } catch (Exception e) { // ctx.setRollbackOnly(); logger.error("unable to update the name at path " + path, e); throw new GreetingServiceException("unable to update the name at path " + path, e); } }
@Override public Forum[] getForumsByStatus(String path, String status) throws ForumServiceException { Forum[] items = null; logIt("get forums under" + path + " with status " + status); try { // Security check String caller = membership.getProfilePathForConnectedIdentifier(); if (caller == null) { throw new ForumServiceException("Could not get connected profile"); } logIt("caller: " + caller); pep.checkSecurity(caller, path, "read"); // Check if given path is valid FactoryResourceIdentifier identifier = binding.lookup(path); // FIXME change restriction of parent. Forum should be created under // any path if (identifier != null && (identifier.getService().equals(SERVICE_NAME) || identifier.getService().equals(CoreService.SERVICE_NAME) || identifier.getService().equals(DocumentService.SERVICE_NAME))) { String servicePattern = ForumService.SERVICE_NAME; String typePattern = Forum.RESOURCE_NAME; String[] forumChildren = browser.listChildrenOfType(path, servicePattern, typePattern); if (forumChildren != null && forumChildren.length > 0) { logIt("Number of forums under " + path + " : " + forumChildren.length); Vector<Forum> forumsVector = new Vector<Forum>(); for (int i = 0; i < forumChildren.length; i++) { logIt("child #" + i + ". " + forumChildren[i]); Forum tmpForum = readForum(forumChildren[i]); if (tmpForum != null && tmpForum.getStatus().equals(status)) { forumsVector.add(tmpForum); } } if (forumsVector != null && forumsVector.size() > 0) { items = forumsVector.toArray(new Forum[forumsVector.size()]); } } } else { throw new ForumServiceException("Given path is not valid."); } } catch (Exception e) { // ctx.setRollbackOnly(); logger.error("Unable to retrieve the forums at path " + path, e); throw new ForumServiceException("Unable to retrieve the forums at path " + path, e); } return items; }
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public String sayHello(String path) throws GreetingServiceException { logger.info("sayHello(...) called"); logger.debug("params : path=" + path); try { // Checking if the connected user has the permission to say-hello the resource giving pep : String caller = membership.getProfilePathForConnectedIdentifier(); pep.checkSecurity(caller, path, "say-hello"); // Performing a lookup in the naming to recover the Resource Identifier FactoryResourceIdentifier identifier = binding.lookup(path); // Checking if this resource identifier is really a resource managed by this service (a Hello // resource) checkResourceType(identifier, Name.RESOURCE_NAME); // STARTING SPECIFIC EXTERNAL SERVICE RESOURCE LOADING OR METHOD CALLS Name name = em.find(Name.class, identifier.getId()); if (name == null) { throw new GreetingServiceException("unable to find a name for id " + identifier.getId()); } // END OF EXTERNAL SERVICE INVOCATION // Building hello message : String message = "Hello dear " + name.getValue() + " !!"; // Using the notification service to throw an event : notification.throwEvent( new Event( path, caller, Name.RESOURCE_NAME, Event.buildEventType(GreetingService.SERVICE_NAME, Name.RESOURCE_NAME, "say-hello"), "")); return message; } catch (Exception e) { // ctx.setRollbackOnly(); logger.error("unable to say hello to the name at path " + path, e); throw new GreetingServiceException("unable to say hello to the name at path " + path, e); } }
/** * @param path the location of the project in the resource tree * @param name * @param status if the project is on alpha, beta or release state * @param summary * @param licence */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void updateProject(String path, String name, String status, String summary, String licence) throws ProjectException { try { if (name == null || name == "") throw new ProjectException("your must specify a name for your project"); if (summary.length() < 10) throw new ProjectException("describe in a more comprehensive manner your project"); if (summary.length() > 255) throw new ProjectException( "Your project description is too long. Please make it smaller than 256 bytes."); String caller = membership.getProfilePathForConnectedIdentifier(); pep.checkSecurity(caller, path, "update"); FactoryResourceIdentifier identifier = binding.lookup(path); checkResourceType(identifier, Project.RESOURCE_NAME); Project project = em.find(Project.class, identifier.getId()); if (project == null) { throw new ProjectException("unable to find a project for id " + identifier.getId()); } project.setName(name); project.setDev_status(status); project.setSummary(summary); project.setLicence(licence); em.merge(project); binding.setProperty( path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + ""); notification.throwEvent( new Event( path, caller, ProjectService.SERVICE_NAME, Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "update"), "")); } catch (Exception e) { ctx.setRollbackOnly(); throw new ProjectException(e); } }
/** * update meta information about the project * * @param path the location of the project in the resource tree * @param os the operating system used by this project * @param topics * @param language natural language used by this project * @param programming_language programming language used by this project * @param intended_audience */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void updateTagsProject( String path, String[] os, String[] topics, String[] language, String[] programming_language, String[] intended_audience) throws ProjectException { try { String caller = membership.getProfilePathForConnectedIdentifier(); pep.checkSecurity(caller, path, "update"); FactoryResourceIdentifier identifier = binding.lookup(path); checkResourceType(identifier, Project.RESOURCE_NAME); Project project = em.find(Project.class, identifier.getId()); if (project == null) { throw new ProjectException("unable to find a project for id " + identifier.getId()); } project.setOs(os); project.setTopics(topics); project.setSpoken_language(language); project.setProgramming_language(programming_language); project.setIntended_audience(intended_audience); em.merge(project); binding.setProperty( path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + ""); notification.throwEvent( new Event( path, caller, ProjectService.SERVICE_NAME, Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "update"), "")); } catch (Exception e) { ctx.setRollbackOnly(); throw new ProjectException(e); } }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FactoryResource findResource(String path) throws FactoryException { try { FactoryResourceIdentifier identifier = binding.lookup(path); if (!identifier.getService().equals(ProjectService.SERVICE_NAME)) { throw new CoreServiceException( "Resource " + identifier + " is not managed by " + ProjectService.SERVICE_NAME); } if (identifier.getType().equals("Project")) { return getProject(path); } throw new CoreServiceException( "Resource " + identifier + " is not managed by " + ProjectService.SERVICE_NAME); } catch (Exception e) { throw new CoreServiceException("unable to find the resource at path " + path, e); } }
/** * Read name with an optional pep check. * * @param path path to the given resource. * @param pepCheck true to make the check. * @return a factoryResource if it can be find. */ @TransactionAttribute(TransactionAttributeType.REQUIRED) private FactoryResource findResource(String path, boolean pepCheck) throws FactoryException { try { FactoryResourceIdentifier identifier = binding.lookup(path); if (!identifier.getService().equals(GreetingService.SERVICE_NAME)) { throw new GreetingServiceException( "Resource " + identifier + " is not managed by " + GreetingService.SERVICE_NAME); } if (identifier.getType().equals(Name.RESOURCE_NAME)) { return readName(path, pepCheck); } throw new GreetingServiceException( "Resource " + identifier + " is not managed by Greeting Service"); } catch (Exception e) { logger.error("unable to find the resource at path " + path, e); throw new GreetingServiceException("unable to find the resource at path " + path, e); } }
/** * Give name at the given path. * * @param pepCheck true to make the check. * @param path the path to the name. * @throws GreetingServiceException if the name can't be find. */ @TransactionAttribute(TransactionAttributeType.SUPPORTS) private Name readName(String path, boolean pepCheck) throws GreetingServiceException { try { // Checking if the connected user has the permission to read the resource giving pep : String caller = membership.getProfilePathForConnectedIdentifier(); if (pepCheck) pep.checkSecurity(caller, path, "read"); // Performing a lookup in the naming to recover the Resource Identifier FactoryResourceIdentifier identifier = binding.lookup(path); // Checking if this resource identifier is really a resource managed by this service (a Hello // resource) checkResourceType(identifier, Name.RESOURCE_NAME); // STARTING SPECIFIC EXTERNAL SERVICE RESOURCE LOADING OR METHOD CALLS Name name = em.find(Name.class, identifier.getId()); if (name == null) { throw new GreetingServiceException("unable to find a name for id " + identifier.getId()); } name.setResourcePath(path); // END OF EXTERNAL SERVICE INVOCATION // Using the notification service to throw an event : notification.throwEvent( new Event( path, caller, Name.RESOURCE_NAME, Event.buildEventType(GreetingService.SERVICE_NAME, Name.RESOURCE_NAME, "read"), "")); return name; } catch (Exception e) { logger.error("unable to read the name at path " + path, e); throw new GreetingServiceException("unable to read the name at path " + path, e); } }
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public ThreadMessage readThreadMessage(String path) throws ForumServiceException { logIt("readThreadMessage(...) called"); logger.debug("params : path=" + path); ThreadMessage msg = null; try { // Security check String caller = membership.getProfilePathForConnectedIdentifier(); if (caller == null) { throw new ForumServiceException("Could not get connected profile"); } logIt("caller: " + caller); pep.checkSecurity(caller, path, "read"); // Look up given path and check resource type FactoryResourceIdentifier identifier = binding.lookup(path); checkResourceType(identifier, ThreadMessage.RESOURCE_NAME); // sFind the entity msg = em.find(ThreadMessage.class, identifier.getId()); if (msg == null) { throw new ForumServiceException("Unable to find a message for id " + identifier.getId()); } // Call the WS to retrieve values that are not stored in // factory HashMap<String, Object> values = forumWS.readThreadMessage(msg.getForumId(), msg.getId()); if (values != null && !values.isEmpty()) { String code = (String) values.get("statusCode"); String msgTxt = (String) values.get("statusMessage"); logIt("Message Code:" + code + " Message: " + msgTxt); if (!code.equals(CollaborationUtils.SUCCESS_CODE) || values.get("ThreadMessage") == null) { throw new ForumServiceException( "Error code recieved from the WS." + " Code" + code + " Message:" + msgTxt); } // FIXME The path is missing in the replies list....Use Browser // method MessageDTO msgWS = (MessageDTO) values.get("ThreadMessage"); if (msgWS != null) { // We don't persist the following // (messageBody,datePosted,numReplies,messageReplies) // so we retrieve values from WS msg.setMessageBody(msgWS.getMessageBody()); msg.setDatePosted(msgWS.getDatePosted()); msg.setNumReplies(msgWS.getNumReplies()); if (msgWS.getMessageReplies() != null) { msg.setMessageReplies(convertHashMap(path, msgWS.getMessageReplies())); } // notify notification.throwEvent( new Event( path, caller, ThreadMessage.RESOURCE_NAME, Event.buildEventType( ForumService.SERVICE_NAME, ThreadMessage.RESOURCE_NAME, "read"), "")); logIt(msg.toString()); } else { throw new ForumServiceException("Error in WS response."); } } else { throw new ForumServiceException("Error in recieving extra details from WS."); } return msg; } catch (Exception e) { logger.error("unable to read the message at path " + path, e); throw new ForumServiceException("unable to read the message at path " + path, e); } }
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public Forum readForum(String path) throws ForumServiceException { logIt("Read forum " + path); try { // Security check String caller = membership.getProfilePathForConnectedIdentifier(); if (caller == null) { throw new ForumServiceException("Could not get connected profile"); } logIt("caller: " + caller); pep.checkSecurity(caller, path, "read"); // Look up given path and check resource type FactoryResourceIdentifier identifier = binding.lookup(path); if (identifier == null) { throw new ForumServiceException("Identifier is null"); } checkResourceType(identifier, Forum.RESOURCE_NAME); // Find the entity Forum forum = em.find(Forum.class, identifier.getId()); if (forum == null) { throw new ForumServiceException("Unable to find a forum for id " + identifier.getId()); } // Call the Mermig WS to retrieve info based on forum.getId() HashMap<String, Object> values = forumWS.readForum(forum.getId()); if (values != null && !values.isEmpty()) { String code = (String) values.get("statusCode"); String msg = (String) values.get("statusMessage"); logIt("Message Code:" + code + " Message: " + msg); if (!code.equals(CollaborationUtils.SUCCESS_CODE) || values.get("forum") == null) { throw new ForumServiceException( "Error code recieved from the WS." + " Code" + code + " Message:" + msg); } // We don't perist the date,status and messages ForumDTO forWS = (ForumDTO) values.get("forum"); forum.setDate(forWS.getDate()); forum.setStatus(forWS.getStatus()); // FIXME The path is missing in the mgs list. // WE NEED TO USE the browse for thread messages if (forWS.getMessages() != null) { forum.setMessages(convertHashMap(path, forWS.getMessages())); } forum.setResourcePath(path); // notify notification.throwEvent( new Event( path, caller, Forum.RESOURCE_NAME, Event.buildEventType(ForumService.SERVICE_NAME, Forum.RESOURCE_NAME, "read"), "")); logIt(forum.toString()); } else { throw new ForumServiceException("Error in recieving extra details from WS."); } return forum; } catch (Exception e) { logger.error("Unable to read the forum at path " + path, e); throw new ForumServiceException("Unable to read the forum at path " + path, e); } }