Changeset 1993 for ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImpl.java
- Timestamp:
- 06/18/12 15:24:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImpl.java
r1992 r1993 1 1 package clarin.cmdi.componentregistry.impl.database; 2 3 import java.security.Principal;4 import java.util.ArrayList;5 import java.util.List;6 7 import org.slf4j.Logger;8 import org.slf4j.LoggerFactory;9 import org.springframework.beans.factory.annotation.Autowired;10 import org.springframework.dao.DataAccessException;11 2 12 3 import clarin.cmdi.componentregistry.ComponentRegistry; … … 14 5 import clarin.cmdi.componentregistry.ComponentStatus; 15 6 import clarin.cmdi.componentregistry.Configuration; 7 import clarin.cmdi.componentregistry.Owner; 16 8 import clarin.cmdi.componentregistry.OwnerUser; 17 9 import clarin.cmdi.componentregistry.UserCredentials; 10 import clarin.cmdi.componentregistry.UserUnauthorizedException; 18 11 import clarin.cmdi.componentregistry.model.RegistryUser; 12 import java.security.Principal; 13 import java.util.ArrayList; 14 import java.util.List; 15 import org.slf4j.Logger; 16 import org.slf4j.LoggerFactory; 17 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.dao.DataAccessException; 19 19 20 20 /** … … 53 53 54 54 @Override 55 public ComponentRegistry getComponentRegistry(boolean userspace, UserCredentials credentials) { 56 ComponentRegistry result = null; 57 if (userspace) { 55 public ComponentRegistry getComponentRegistry(ComponentStatus status, Owner owner, UserCredentials credentials) throws UserUnauthorizedException { 56 switch (status) { 57 case DEVELOPMENT: 58 return getDevelopmentRegistry(owner, credentials); 59 case PUBLIC: 60 return getPublicRegistry(); 61 default: 62 // TODO: Add support for other status types 63 throw new UnsupportedOperationException("Unsupported component status" + status); 64 } 65 } 66 67 private ComponentRegistry getDevelopmentRegistry(Owner owner, UserCredentials credentials) throws IllegalArgumentException, DataAccessException, UserUnauthorizedException { 68 if (owner == null || owner instanceof OwnerUser) { 58 69 RegistryUser user = getOrCreateUser(credentials); 59 70 if (user != null) { 71 if (owner != null && !user.getId().equals(owner.getId())) { 72 throw new UserUnauthorizedException("User cannot access other user's development registry"); 73 } 74 60 75 try { 61 re sult =getNewComponentRegistryForUser(user.getId());76 return getNewComponentRegistryForUser(user.getId()); 62 77 } catch (DataAccessException ex) { 63 78 LOG.error("Could not retrieve or create user", ex); … … 68 83 } 69 84 } else { 70 result = getPublicRegistry(); 85 // TODO: Support group owners 86 throw new UnsupportedOperationException("Group owners not supported"); 71 87 } 72 return result;73 88 } 74 89 75 90 @Override 76 public ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, String userId) {91 public ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, ComponentStatus status, Owner owner) { 77 92 try { 78 RegistryUser user = userDao.getById(Integer.parseInt(userId)); 93 RegistryUser user; 94 if (owner instanceof OwnerUser) { 95 user = userDao.getById(owner.getId()); 96 } else { 97 // TODO: Implement for groups 98 throw new UnsupportedOperationException("Groups not implemented yet"); 99 } 79 100 ComponentRegistry result = null; 80 101 if (user != null) {
Note: See TracChangeset
for help on using the changeset viewer.