Ignore:
Timestamp:
06/18/12 15:24:30 (12 years ago)
Author:
twagoo
Message:

ComponentRegistryFactory? now using ComponentStatus? and Owner instead of userId and userspace parameter.

Refs #142 and #143

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImpl.java

    r1992 r1993  
    11package 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;
    112
    123import clarin.cmdi.componentregistry.ComponentRegistry;
     
    145import clarin.cmdi.componentregistry.ComponentStatus;
    156import clarin.cmdi.componentregistry.Configuration;
     7import clarin.cmdi.componentregistry.Owner;
    168import clarin.cmdi.componentregistry.OwnerUser;
    179import clarin.cmdi.componentregistry.UserCredentials;
     10import clarin.cmdi.componentregistry.UserUnauthorizedException;
    1811import clarin.cmdi.componentregistry.model.RegistryUser;
     12import java.security.Principal;
     13import java.util.ArrayList;
     14import java.util.List;
     15import org.slf4j.Logger;
     16import org.slf4j.LoggerFactory;
     17import org.springframework.beans.factory.annotation.Autowired;
     18import org.springframework.dao.DataAccessException;
    1919
    2020/**
     
    5353
    5454    @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) {
    5869            RegistryUser user = getOrCreateUser(credentials);
    5970            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
    6075                try {
    61                     result = getNewComponentRegistryForUser(user.getId());
     76                    return getNewComponentRegistryForUser(user.getId());
    6277                } catch (DataAccessException ex) {
    6378                    LOG.error("Could not retrieve or create user", ex);
     
    6883            }
    6984        } else {
    70             result = getPublicRegistry();
     85            // TODO: Support group owners
     86            throw new UnsupportedOperationException("Group owners not supported");
    7187        }
    72         return result;
    7388    }
    7489
    7590    @Override
    76     public ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, String userId) {
     91    public ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, ComponentStatus status, Owner owner) {
    7792        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            }
    79100            ComponentRegistry result = null;
    80101            if (user != null) {
Note: See TracChangeset for help on using the changeset viewer.