/**
  * Adds a new project to the metaproject. This sets up the name of the project and the description
  * of the project in the metaproject. (Location is not set/used by this implementation - not all
  * implementations use pprj files anymore).
  *
  * @param newProjectSettings The info about the new project
  */
 private void addProjectToMetaProject(ProjectId projectId, NewProjectSettings newProjectSettings) {
   MetaProject mp = getMetaProject();
   ProjectInstance pi = mp.createProject(projectId.getId());
   pi.setDescription(newProjectSettings.getProjectDescription());
   final Instance protegeInstance = pi.getProtegeInstance();
   final KnowledgeBase kb = protegeInstance.getKnowledgeBase();
   final Slot displayNameSlot = kb.getSlot("displayName");
   protegeInstance.setOwnSlotValue(displayNameSlot, newProjectSettings.getDisplayName());
   User user = mp.getUser(newProjectSettings.getProjectOwner().getUserName());
   pi.setOwner(user);
   OWLAPIMetaProjectStore.getStore().saveMetaProject(this);
 }
 private ProjectInstance getProjectInstance(ProjectId projectId) throws UnknownProjectException {
   try {
     READ_LOCK.lock();
     MetaProject metaProject = getMetaProject();
     ProjectInstance pi = metaProject.getProject(projectId.getId());
     if (pi == null) {
       throw new UnknownProjectException(projectId);
     }
     return pi;
   } finally {
     READ_LOCK.unlock();
   }
 }
 /**
  * Detemines if the signed in user is the owner of the specified project
  *
  * @param projectId The project id
  * @return <code>true</code> if the project exists AND there is a user signed in AND the signed in
  *     user is the owner of the project, otherwise <code>false</code>.
  */
 protected boolean isSignedInUserProjectOwner(ProjectId projectId) {
   UserId userId = getUserInSession();
   if (userId.isGuest()) {
     return false;
   }
   MetaProjectManager mpm = getMetaProjectManager();
   MetaProject metaProject = mpm.getMetaProject();
   ProjectInstance project = metaProject.getProject(projectId.getId());
   if (project == null) {
     return false;
   }
   User owner = project.getOwner();
   return owner != null && userId.getUserName().equals(owner.getName());
 }
 public synchronized Set<ProjectId> getProjects() {
   try {
     READ_LOCK.lock();
     MetaProject metaProject = getMetaProject();
     Set<ProjectInstance> projectInstances = metaProject.getProjects();
     Set<ProjectId> result = new HashSet<ProjectId>(projectInstances.size());
     for (ProjectInstance pi : projectInstances) {
       String projectName = pi.getName();
       result.add(ProjectId.get(projectName));
     }
     return result;
   } finally {
     READ_LOCK.unlock();
   }
 }
 public UserData registerUser(String userName, String email, String password)
     throws UserRegistrationException {
   checkNotNull(userName);
   checkNotNull(email);
   checkNotNull(password);
   User existingUser = metaproject.getUser(userName);
   if (existingUser != null) {
     throw new UserNameAlreadyExistsException(userName);
   }
   for (User user : metaproject.getUsers()) {
     if (email.equals(user.getEmail())) {
       throw new UserEmailAlreadyExistsException(email);
     }
   }
   User newUser = metaproject.createUser(userName, password);
   return AuthenticationUtil.createUserData(UserId.getUserId(newUser.getName()));
 }
 @Override
 public ProjectDetails getProjectDetails(ProjectId projectId) throws UnknownProjectException {
   ProjectInstance pi = metaproject.getProject(projectId.getId());
   if (pi == null) {
     throw new UnknownProjectException(projectId);
   }
   return createProjectDetailsFromProjectInstance(pi);
 }
 /**
  * Determines if the signed in user is an admin.
  *
  * @return <code>true</code> if there is a user signed in AND the signed in user corresponds to a
  *     user which exists where that user is an admin, otherwise <code>false</code>
  */
 protected boolean isSignedInUserAdmin() {
   UserId userId = getUserInSession();
   if (userId.isGuest()) {
     return false;
   }
   MetaProjectManager mpm = getMetaProjectManager();
   MetaProject metaProject = mpm.getMetaProject();
   User user = metaProject.getUser(userId.getUserName());
   if (user == null) {
     return false;
   }
   for (Group group : user.getGroups()) {
     if (OntologyShareAccessConstants.ADMIN_GROUP.equals(group.getName())) {
       return true;
     }
   }
   return false;
 }
 private void setPropertyValue(ProjectId projectId, String propertyName, String propertyValue) {
   try {
     WRITE_LOCK.lock();
     ProjectInstance pi = getProjectInstance(projectId);
     MetaProject mp = getMetaProject();
     PropertyValue pv = mp.createPropertyValue(propertyName, propertyValue);
     Set<PropertyValue> propertyValues = new HashSet<PropertyValue>(pi.getPropertyValues());
     for (Iterator<PropertyValue> it = propertyValues.iterator(); it.hasNext(); ) {
       PropertyValue curPv = it.next();
       if (curPv.getPropertyName().equals(propertyName)) {
         it.remove();
       }
     }
     propertyValues.add(pv);
     pi.setPropertyValues(propertyValues);
     //            Should be threaded off
     save();
   } finally {
     WRITE_LOCK.unlock();
   }
 }
 public List<ProjectDetails> getListableReadableProjects(UserId userId) {
   Policy policy = metaproject.getPolicy();
   User user = policy.getUserByName(userId.getUserName());
   List<ProjectDetails> result = new ArrayList<ProjectDetails>();
   for (ProjectInstance projectInstance : metaproject.getProjects()) {
     final String name = projectInstance.getName();
     if (name != null && ProjectId.isWelFormedProjectId(name)) {
       final ProjectId projectId = ProjectId.get(name);
       if (isAuthorisedToReadAndList(policy, user, projectInstance)) {
         OWLAPIProjectDocumentStore ds =
             OWLAPIProjectDocumentStore.getProjectDocumentStore(projectId);
         if (ds.exists()) {
           final ProjectDetails projectDetails =
               createProjectDetailsFromProjectInstance(projectInstance);
           result.add(projectDetails);
         }
       }
     }
   }
   return result;
 }
Ejemplo n.º 10
0
 public void dispose() {
   metaproject.dispose();
   synchronized (this) {
     notifyAll();
   }
 }