Changeset 1993


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

Location:
ComponentRegistry/trunk/ComponentRegistry/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistryFactory.java

    r1698 r1993  
    1515    List<ComponentRegistry> getAllUserRegistries();
    1616
    17     ComponentRegistry getComponentRegistry(boolean userspace, UserCredentials credentials);
     17    /**
     18     * Gets the specified registry
     19     *
     20     * @param status status of the registry
     21     * @param owner owner of the registry. Passing null will assume the authenticated user as a {@link OwnerUser}
     22     * @param credentials credentials that authenticate user, can be left null if requested registry has a public status
     23     * @return
     24     */
     25    ComponentRegistry getComponentRegistry(ComponentStatus status, Owner owner, UserCredentials credentials) throws UserUnauthorizedException;
    1826
    19     ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, String userId);
     27    ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, ComponentStatus status, Owner owner);
    2028
    2129    ComponentRegistry getPublicRegistry();
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/AdminHomePage.java

    r1778 r1993  
    2929import clarin.cmdi.componentregistry.ComponentRegistryException;
    3030import clarin.cmdi.componentregistry.ComponentRegistryFactory;
     31import clarin.cmdi.componentregistry.ComponentStatus;
    3132import clarin.cmdi.componentregistry.impl.database.AdminRegistry;
    3233import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao;
     
    275276        DefaultMutableTreeNode componentsNode = new DefaultMutableTreeNode(new DisplayDataNode("Components", false));
    276277        parent.add(componentsNode);
    277         add(componentsNode, registry.getComponentDescriptions(), false, registry.isPublic());
     278        add(componentsNode, registry.getComponentDescriptions(), false, registry.getStatus());
    278279
    279280        DefaultMutableTreeNode profilesNode = new DefaultMutableTreeNode(new DisplayDataNode("Profiles", false));
    280281        parent.add(profilesNode);
    281         add(profilesNode, registry.getProfileDescriptions(), false, registry.isPublic());
     282        add(profilesNode, registry.getProfileDescriptions(), false, registry.getStatus());
    282283
    283284        DefaultMutableTreeNode deletedCompNode = new DefaultMutableTreeNode(new DisplayDataNode("Deleted Components", true));
     
    285286
    286287        List<ComponentDescription> deletedComponentDescriptions = registry.getDeletedComponentDescriptions();
    287         add(deletedCompNode, deletedComponentDescriptions, true, registry.isPublic());
     288        add(deletedCompNode, deletedComponentDescriptions, true, registry.getStatus());
    288289
    289290        DefaultMutableTreeNode deletedProfNode = new DefaultMutableTreeNode(new DisplayDataNode("Deleted Profiles", true));
    290291        parent.add(deletedProfNode);
    291292        List<ProfileDescription> deletedProfileDescriptions = registry.getDeletedProfileDescriptions();
    292         add(deletedProfNode, deletedProfileDescriptions, true, registry.isPublic());
    293     }
    294 
    295     private void add(DefaultMutableTreeNode parent, List<? extends AbstractDescription> descs, boolean isDeleted, boolean isPublic) {
     293        add(deletedProfNode, deletedProfileDescriptions, true, registry.getStatus());
     294    }
     295
     296    private void add(DefaultMutableTreeNode parent, List<? extends AbstractDescription> descs, boolean isDeleted, ComponentStatus status) {
    296297        for (AbstractDescription desc : descs) {
    297             DefaultMutableTreeNode child = new DefaultMutableTreeNode(new DisplayDataNode(desc.getName(), isDeleted, desc, isPublic));
     298            DefaultMutableTreeNode child = new DefaultMutableTreeNode(new DisplayDataNode(desc.getName(), isDeleted, desc, status));
    298299            parent.add(child);
    299300        }
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/CMDItemInfo.java

    r1364 r1993  
    11package clarin.cmdi.componentregistry.frontend;
    22
     3import clarin.cmdi.componentregistry.ComponentStatus;
    34import java.io.Serializable;
    45
     
    9293    }
    9394
    94 
    95     public boolean isInUserWorkSpace() {
    96         return !displayNode.isPublic();
     95   
     96    public ComponentStatus getStatus() {
     97        return displayNode.getStatus();
    9798    }
    98 
     99       
    99100    public void setForceUpdate(boolean forceUpdate) {
    100101        this.forceUpdate = forceUpdate;
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/DisplayDataNode.java

    r1364 r1993  
    11package clarin.cmdi.componentregistry.frontend;
    22
     3import clarin.cmdi.componentregistry.ComponentStatus;
    34import java.io.Serializable;
    45
     
    1112    private final boolean isDeleted;
    1213    private AbstractDescription desc;
    13     private final boolean isPublic;
     14    private final ComponentStatus status;
    1415
    1516    public DisplayDataNode(String name, boolean isDeleted) {
    16         this(name, isDeleted, null, false);
     17        // TODO: what is sensible default status?
     18        this(name, isDeleted, null, ComponentStatus.DEVELOPMENT);
    1719    }
    1820
    19     public DisplayDataNode(String name, boolean isDeleted, AbstractDescription desc, boolean isPublic) {
    20         this.name = name;
    21         this.isDeleted = isDeleted;
    22         this.desc = desc;
    23         this.isPublic = isPublic;
     21    public DisplayDataNode(String name, boolean isDeleted, AbstractDescription desc, ComponentStatus status) {
     22        this.name = name;
     23        this.isDeleted = isDeleted;
     24        this.desc = desc;
     25        this.status = status;
    2426    }
    2527
    2628    /**
    2729     * Can be null for non leaves.
     30     *
    2831     * @return
    2932     */
    3033    public AbstractDescription getDescription() {
    31         return desc;
     34        return desc;
    3235    }
    3336
    3437    public boolean isDeleted() {
    35         return isDeleted;
     38        return isDeleted;
    3639    }
    3740
    3841    @Override
    3942    public String toString() {
    40         return name;
     43        return name;
    4144    }
    4245
    43     public boolean isPublic() {
    44         return isPublic;
     46    public ComponentStatus getStatus() {
     47        return status;
    4548    }
    46 
    4749}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/AdminRegistry.java

    r1372 r1993  
    1414import clarin.cmdi.componentregistry.ComponentRegistryException;
    1515import clarin.cmdi.componentregistry.ComponentRegistryFactory;
     16import clarin.cmdi.componentregistry.ComponentStatus;
    1617import clarin.cmdi.componentregistry.DeleteFailedException;
    1718import clarin.cmdi.componentregistry.MDMarshaller;
     19import clarin.cmdi.componentregistry.OwnerUser;
    1820import clarin.cmdi.componentregistry.UserUnauthorizedException;
    1921import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     
    2527
    2628public class AdminRegistry {
     29
    2730    private final static Logger LOG = LoggerFactory.getLogger(AdminRegistry.class);
    28 
    2931    private ComponentRegistryFactory componentRegistryFactory;
    3032    private ProfileDescriptionDao profileDescriptionDao;
     
    118120    private ComponentRegistry getRegistry(Principal userPrincipal, AbstractDescription desc, CMDItemInfo info) {
    119121        ComponentRegistry registry = componentRegistryFactory.getPublicRegistry();
    120         if (info.isInUserWorkSpace()) {
    121             registry = componentRegistryFactory.getOtherUserComponentRegistry(userPrincipal, desc.getUserId());
     122        //TODO: More generic check
     123        if (info.getStatus() == ComponentStatus.DEVELOPMENT /* || info.getStatus() == ComponentStatus.PRIVATE */) {
     124            registry = componentRegistryFactory.getOtherUserComponentRegistry(userPrincipal, info.getStatus(), new OwnerUser(Integer.parseInt(desc.getUserId())));
    122125        }
    123126        return registry;
    124127    }
    125 
    126128}
  • 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) {
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1894 r1993  
    44import clarin.cmdi.componentregistry.ComponentRegistryException;
    55import clarin.cmdi.componentregistry.ComponentRegistryFactory;
     6import clarin.cmdi.componentregistry.ComponentStatus;
    67import clarin.cmdi.componentregistry.DeleteFailedException;
     8import clarin.cmdi.componentregistry.Owner;
    79import clarin.cmdi.componentregistry.UserCredentials;
    810import clarin.cmdi.componentregistry.UserUnauthorizedException;
     
    4850@Path("/registry")
    4951public class ComponentRegistryRestService {
    50    
     52
    5153    @Context
    5254    private UriInfo uriInfo;
     
    6567    @Inject(value = "componentRegistryFactory")
    6668    private ComponentRegistryFactory componentRegistryFactory;
    67    
    68     private ComponentRegistry getRegistry(boolean userspace) {
     69
     70    /**
     71     * Converts userspace boolean to component status. Temporary solution!!!
     72     *
     73     * TODO: Replace all calls to getRegistry that use this by calls using ComponentStatus
     74     * @param userSpace
     75     * @return
     76     * @deprecated All calls should go directly to {@link #getRegistry(clarin.cmdi.componentregistry.ComponentStatus)}
     77     */
     78    @Deprecated
     79    private static ComponentStatus getStatus(boolean userSpace) {
     80        if (userSpace) {
     81            return ComponentStatus.DEVELOPMENT;
     82        } else {
     83            return ComponentStatus.PUBLIC;
     84        }
     85    }
     86
     87    private ComponentRegistry getRegistry(ComponentStatus status) {
    6988        Principal userPrincipal = security.getUserPrincipal();
    7089        UserCredentials userCredentials = getUserCredentials(userPrincipal);
    71         return getRegistry(userspace, userCredentials);
    72     }
    73    
    74     private ComponentRegistry getRegistry(boolean userspace, UserCredentials userCredentials) {
    75         return componentRegistryFactory.getComponentRegistry(userspace, userCredentials);
     90        return getRegistry(status, null, userCredentials);
     91    }
     92
     93    private ComponentRegistry getRegistry(ComponentStatus status, Owner owner, UserCredentials userCredentials) {
     94        try {
     95            return componentRegistryFactory.getComponentRegistry(status, owner, userCredentials);
     96        } catch (UserUnauthorizedException uuEx) {
     97            //TODO: Throw actual exception and catch nicely
     98            throw new RuntimeException("Cannot access requested registry", uuEx);
     99        }
    76100    }
    77101
     
    88112        return principal;
    89113    }
    90    
     114
    91115    private UserCredentials getUserCredentials(Principal userPrincipal) {
    92116        UserCredentials userCredentials = null;
     
    96120        return userCredentials;
    97121    }
    98    
     122
    99123    @GET
    100124    @Path("/components")
     
    102126    public List<ComponentDescription> getRegisteredComponents(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    103127        long start = System.currentTimeMillis();
    104         List<ComponentDescription> components = getRegistry(userspace).getComponentDescriptions();
     128        List<ComponentDescription> components = getRegistry(getStatus(userspace)).getComponentDescriptions();
    105129        LOG.info("Releasing " + components.size() + " registered components into the world (" + (System.currentTimeMillis() - start)
    106130                + " millisecs)");
    107131        return components;
    108132    }
    109    
     133
    110134    @GET
    111135    @Path("/profiles")
     
    114138            @QueryParam(METADATA_EDITOR_PARAM) @DefaultValue("false") boolean metadataEditor) throws ComponentRegistryException {
    115139        long start = System.currentTimeMillis();
    116        
     140
    117141        List<ProfileDescription> profiles;
    118142        if (metadataEditor) {
    119             profiles = getRegistry(userspace).getProfileDescriptionsForMetadaEditor();
     143            profiles = getRegistry(getStatus(userspace)).getProfileDescriptionsForMetadaEditor();
    120144        } else {
    121             profiles = getRegistry(userspace).getProfileDescriptions();
    122         }
    123        
     145            profiles = getRegistry(getStatus(userspace)).getProfileDescriptions();
     146        }
     147
    124148        LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start)
    125149                + " millisecs)");
    126150        return profiles;
    127151    }
    128    
     152
    129153    @GET
    130154    @Path("/components/{componentId}")
     
    133157            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    134158        LOG.info("Component with id: " + componentId + " is requested.");
    135         CMDComponentSpec mdComponent = getRegistry(userspace).getMDComponent(componentId);
     159        CMDComponentSpec mdComponent = getRegistry(getStatus(userspace)).getMDComponent(componentId);
    136160        if (mdComponent == null) {
    137161            return Response.status(Status.NOT_FOUND).build();
     
    140164        }
    141165    }
    142    
     166
    143167    @GET
    144168    @Path("/components/{componentId}/{rawType}")
     
    157181            if ("xml".equalsIgnoreCase(rawType)) {
    158182                result = new StreamingOutput() {
    159                    
     183
    160184                    @Override
    161185                    public void write(OutputStream output) throws IOException, WebApplicationException {
     
    170194            } else if ("xsd".equalsIgnoreCase(rawType)) {
    171195                result = new StreamingOutput() {
    172                    
     196
    173197                    @Override
    174198                    public void write(OutputStream output) throws IOException, WebApplicationException {
     
    179203                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    180204                        }
    181                        
     205
    182206                    }
    183207                };
     
    192216        }
    193217    }
    194    
     218
    195219    public ComponentRegistry findRegistry(String id, RegistryClosure<? extends AbstractDescription> clos) throws ComponentRegistryException {
    196220        AbstractDescription desc = null;
    197         ComponentRegistry result = getRegistry(false);
     221        ComponentRegistry result = getRegistry(getStatus(false));
    198222        desc = clos.getDescription(result, id);
    199223        if (desc == null) {
     
    209233        return result;
    210234    }
    211    
     235
    212236    @GET
    213237    @Path("/profiles/{profileId}")
     
    216240            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    217241        LOG.info("Profile with id: " + profileId + " is requested.");
    218         CMDComponentSpec mdProfile = getRegistry(userspace).getMDProfile(profileId);
     242        CMDComponentSpec mdProfile = getRegistry(getStatus(userspace)).getMDProfile(profileId);
    219243        if (mdProfile == null) {
    220244            return Response.status(Status.NOT_FOUND).build();
     
    223247        }
    224248    }
    225    
     249
    226250    @GET
    227251    @Path("/components/usage/{componentId}")
     
    230254        try {
    231255            final long start = System.currentTimeMillis();
    232             ComponentRegistry registry = getRegistry(userspace);
     256            ComponentRegistry registry = getRegistry(getStatus(userspace));
    233257            List<ComponentDescription> components = registry.getUsageInComponents(componentId);
    234258            List<ProfileDescription> profiles = registry.getUsageInProfiles(componentId);
    235            
     259
    236260            LOG.info("Found " + components.size() + " components and " + profiles.size() + " profiles that use component " + componentId
    237261                    + " (" + (System.currentTimeMillis() - start) + " millisecs)");
    238            
     262
    239263            List<AbstractDescription> usages = new ArrayList<AbstractDescription>(components.size() + profiles.size());
    240264            usages.addAll(components);
    241265            usages.addAll(profiles);
    242            
     266
    243267            return usages;
    244268        } catch (ComponentRegistryException e) {
     
    247271        }
    248272    }
    249    
     273
    250274    @GET
    251275    @Path("/profiles/{profileId}/comments")
     
    254278        long start = System.currentTimeMillis();
    255279        final Principal principal = security.getUserPrincipal();
    256         List<Comment> comments = getRegistry(userspace).getCommentsInProfile(profileId, principal);
     280        List<Comment> comments = getRegistry(getStatus(userspace)).getCommentsInProfile(profileId, principal);
    257281        LOG.info("Releasing " + comments.size() + " registered comments in Profile into the world (" + (System.currentTimeMillis() - start)
    258282                + " millisecs)");
    259283        return comments;
    260284    }
    261    
     285
    262286    @GET
    263287    @Path("/components/{componentId}/comments")
     
    266290        long start = System.currentTimeMillis();
    267291        final Principal principal = security.getUserPrincipal();
    268         List<Comment> comments = getRegistry(userspace).getCommentsInComponent(componentId, principal);
     292        List<Comment> comments = getRegistry(getStatus(userspace)).getCommentsInComponent(componentId, principal);
    269293        LOG.info("Releasing " + comments.size() + " registered comments in Component into the world (" + (System.currentTimeMillis() - start)
    270294                + " millisecs)");
    271295        return comments;
    272296    }
    273    
     297
    274298    @GET
    275299    @Path("/profiles/{profileId}/comments/{commentId}")
     
    278302        LOG.info(" Comments of component with id" + commentId + " are requested.");
    279303        final Principal principal = security.getUserPrincipal();
    280         return getRegistry(userspace).getSpecifiedCommentInProfile(profileId, commentId, principal);
    281     }
    282    
     304        return getRegistry(getStatus(userspace)).getSpecifiedCommentInProfile(profileId, commentId, principal);
     305    }
     306
    283307    @GET
    284308    @Path("/components/{componentId}/comments/{commentId}")
     
    287311        LOG.info(" Comments of component with id" + commentId + " are requested.");
    288312        final Principal principal = security.getUserPrincipal();
    289         return getRegistry(userspace).getSpecifiedCommentInComponent(componentId, commentId, principal);
     313        return getRegistry(getStatus(userspace)).getSpecifiedCommentInComponent(componentId, commentId, principal);
    290314    }
    291315
     
    309333        }
    310334    }
    311    
     335
    312336    @POST
    313337    @Path("/profiles/{profileId}/comments/{commentId}")
     
    320344        }
    321345    }
    322    
     346
    323347    @POST
    324348    @Path("/components/{componentId}/comments/{commentId}")
     
    331355        }
    332356    }
    333    
     357
    334358    @POST
    335359    @Path("/profiles/{profileId}/publish")
     
    340364        try {
    341365            Principal principal = checkAndGetUserPrincipal();
    342             ProfileDescription desc = getRegistry(true).getProfileDescription(profileId);
     366            ProfileDescription desc = getRegistry(getStatus(true)).getProfileDescription(profileId);
    343367            if (desc != null) {
    344368                updateDescription(desc, name, description, domainName, group);
     
    355379        }
    356380    }
    357    
     381
    358382    @POST
    359383    @Path("/profiles/{profileId}/update")
     
    366390            Principal principal = checkAndGetUserPrincipal();
    367391            UserCredentials userCredentials = getUserCredentials(principal);
    368             ProfileDescription desc = getRegistry(userspace).getProfileDescription(profileId);
     392            ProfileDescription desc = getRegistry(getStatus(userspace)).getProfileDescription(profileId);
    369393            if (desc != null) {
    370394                updateDescription(desc, name, description, domainName, group);
     
    380404            return Response.status(Status.UNAUTHORIZED).entity(ex.getMessage()).build();
    381405        }
    382        
     406
    383407    }
    384408
     
    402426        }
    403427    }
    404    
     428
    405429    @POST
    406430    @Path("/components/{componentId}/publish")
     
    412436        try {
    413437            Principal principal = checkAndGetUserPrincipal();
    414             ComponentDescription desc = getRegistry(true).getComponentDescription(componentId);
     438            // TODO: Get status from parameter
     439            ComponentDescription desc = getRegistry(getStatus(true)).getComponentDescription(componentId);
    415440            if (desc != null) {
    416441                updateDescription(desc, name, description, domainName, group);
     
    427452        }
    428453    }
    429    
     454
    430455    @POST
    431456    @Path("/components/{componentId}/update")
     
    437462        try {
    438463            Principal principal = checkAndGetUserPrincipal();
    439             ComponentDescription desc = getRegistry(userspace).getComponentDescription(componentId);
     464            ComponentDescription desc = getRegistry(getStatus(userspace)).getComponentDescription(componentId);
    440465            if (desc != null) {
    441466                updateDescription(desc, name, description, domainName, group);
     
    452477        }
    453478    }
    454    
     479
    455480    private void updateDescription(AbstractDescription desc, String name, String description, String domainName, String group) {
    456481        desc.setName(name);
     
    460485        desc.setRegistrationDate(AbstractDescription.createNewDate());
    461486    }
    462    
     487
    463488    @DELETE
    464489    @Path("/components/{componentId}")
     
    467492        try {
    468493            Principal principal = checkAndGetUserPrincipal();
    469             ComponentRegistry registry = getRegistry(userspace);
     494            ComponentRegistry registry = getRegistry(getStatus(userspace));
    470495            LOG.info("Component with id: " + componentId + " set for deletion.");
    471496            registry.deleteMDComponent(componentId, principal, false);
     
    486511        return Response.ok().build();
    487512    }
    488    
     513
    489514    @DELETE
    490515    @Path("/profiles/{profileId}")
     
    494519            Principal principal = checkAndGetUserPrincipal();
    495520            LOG.info("Profile with id: " + profileId + " set for deletion.");
    496             getRegistry(userspace).deleteMDProfile(profileId, principal);
     521            getRegistry(getStatus(userspace)).deleteMDProfile(profileId, principal);
    497522        } catch (DeleteFailedException e) {
    498523            LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
     
    511536        return Response.ok().build();
    512537    }
    513    
     538
    514539    @DELETE
    515540    @Path("/profiles/{profileId}/comments/{commentId}")
     
    518543        try {
    519544            final Principal principal = checkAndGetUserPrincipal();
    520             final ComponentRegistry registry = getRegistry(userspace);
     545            final ComponentRegistry registry = getRegistry(getStatus(userspace));
    521546            final Comment comment = registry.getSpecifiedCommentInProfile(profileId, commentId, principal);
    522547            if (comment != null && profileId.equals(comment.getProfileDescriptionId())) {
     
    542567        return Response.ok().build();
    543568    }
    544    
     569
    545570    @DELETE
    546571    @Path("/components/{componentId}/comments/{commentId}")
     
    549574        try {
    550575            final Principal principal = checkAndGetUserPrincipal();
    551             final ComponentRegistry registry = getRegistry(userspace);
     576            final ComponentRegistry registry = getRegistry(getStatus(userspace));
    552577            final Comment comment = registry.getSpecifiedCommentInComponent(componentId, commentId, principal);
    553578            if (comment != null && componentId.equals(comment.getComponentDescriptionId())) {
     
    573598        return Response.ok().build();
    574599    }
    575    
     600
    576601    @GET
    577602    @Path("/profiles/{profileId}/{rawType}")
     
    588613            checkAndThrowDescription(desc, profileId);
    589614            String fileName = desc.getName() + "." + rawType;
    590            
     615
    591616            if ("xml".equalsIgnoreCase(rawType)) {
    592617                result = new StreamingOutput() {
    593                    
     618
    594619                    @Override
    595620                    public void write(OutputStream output) throws IOException, WebApplicationException {
     
    604629            } else if ("xsd".equalsIgnoreCase(rawType)) {
    605630                result = new StreamingOutput() {
    606                    
     631
    607632                    @Override
    608633                    public void write(OutputStream output) throws IOException, WebApplicationException {
     
    625650        }
    626651    }
    627    
     652
    628653    private void checkAndThrowDescription(AbstractDescription desc, String id) {
    629654        if (desc == null) {
     
    631656        }
    632657    }
    633    
     658
    634659    private Response createDownloadResponse(StreamingOutput result, String fileName) {
    635660        //Making response so it triggers browsers native save as dialog.
     
    637662                "attachment; filename=\"" + fileName + "\"").entity(result).build();
    638663        return response;
    639        
    640     }
    641    
     664
     665    }
     666
    642667    @POST
    643668    @Path("/profiles")
     
    663688        }
    664689    }
    665    
     690
    666691    @POST
    667692    @Path("/components")
     
    687712        }
    688713    }
    689    
     714
    690715    @POST
    691716    @Path("/components/{componentId}/comments")
     
    700725                throw new UserUnauthorizedException("Cannot materialize authenticated user");
    701726            }
    702             ComponentRegistry registry = getRegistry(userspace, userCredentials);
     727            // TODO: Add user/group param
     728            ComponentRegistry registry = getRegistry(getStatus(userspace), null, userCredentials);
    703729            ComponentDescription description = registry.getComponentDescription(componentId);
    704730            if (description != null) {
     
    713739        }
    714740    }
    715    
     741
    716742    @POST
    717743    @Path("/profiles/{profileId}/comments")
     
    726752                throw new UserUnauthorizedException("Cannot materialize authenticated user");
    727753            }
    728             ComponentRegistry registry = getRegistry(userspace, userCredentials);
     754            // TODO: Add user/group param
     755            ComponentRegistry registry = getRegistry(getStatus(userspace), null, userCredentials);
    729756            ProfileDescription description = registry.getProfileDescription(profileId);
    730757            if (description != null) {
     
    739766        }
    740767    }
    741    
     768
    742769    @GET
    743770    @Path("/pingSession")
     
    754781        return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build();
    755782    }
    756    
     783
    757784    private Response register(InputStream input, AbstractDescription desc, UserCredentials userCredentials, boolean userspace,
    758785            RegisterAction action) {
    759786        try {
    760             ComponentRegistry registry = getRegistry(userspace, userCredentials);
     787            // TODO: Add user/group param
     788            ComponentRegistry registry = getRegistry(getStatus(userspace), null, userCredentials);
    761789            DescriptionValidator descriptionValidator = new DescriptionValidator(desc);
    762             MDValidator validator = new MDValidator(input, desc, registry, getRegistry(true), componentRegistryFactory.getPublicRegistry());
     790            MDValidator validator = new MDValidator(input, desc, registry, getRegistry(getStatus(true)), componentRegistryFactory.getPublicRegistry());
    763791            RegisterResponse response = new RegisterResponse();
    764792            response.setIsInUserSpace(userspace);
     
    798826        }
    799827    }
    800    
     828
    801829    private Response registerComment(InputStream input, ComponentRegistry registry, boolean userspace,
    802830            AbstractDescription description, Principal principal, UserCredentials userCredentials) {
     
    818846                    }
    819847                }
    820                
     848
    821849                int returnCode = registry.registerComment(com, principal.getName());
    822850                if (returnCode == 0) {
     
    844872        }
    845873    }
    846    
     874
    847875    private ComponentDescription createNewComponentDescription() {
    848876        ComponentDescription desc = ComponentDescription.createNewDescription();
     
    850878        return desc;
    851879    }
    852    
     880
    853881    private ProfileDescription createNewProfileDescription() {
    854882        ProfileDescription desc = ProfileDescription.createNewDescription();
     
    856884        return desc;
    857885    }
    858    
     886
    859887    private Comment createNewComment() {
    860888        Comment com = Comment.createANewComment();
    861889        return com;
    862890    }
    863    
     891
    864892    private String createXlink(String id) {
    865893        URI uri = uriInfo.getRequestUriBuilder().path(id).build();
    866894        return uri.toString();
    867895    }
    868    
     896
    869897    private void validate(RegisterResponse response, Validator... validators) {
    870898        for (Validator validator : validators) {
     
    876904        }
    877905    }
    878    
     906
    879907    private void validateComment(CommentResponse response, Validator... validators) {
    880908        for (Validator validator : validators) {
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/frontend/CMDItemInfoTest.java

    r1364 r1993  
    11package clarin.cmdi.componentregistry.frontend;
    22
     3import clarin.cmdi.componentregistry.ComponentStatus;
    34import static org.junit.Assert.assertEquals;
    45import static org.junit.Assert.assertFalse;
     
    1415    @Test
    1516    public void testGetUserDir() throws Exception {
    16         CMDItemInfo info = new CMDItemInfo();
    17         //info.setDataNode(new FileNode(createFile("users/user1/components/c_123/description.xml"), false));
    18         info.setDataNode(new DisplayDataNode("test", false, createDescription(), false));
    19         assertTrue(info.isDeletable());
    20         assertFalse(info.isUndeletable());
    21         assertTrue(info.isEditable());
    22         assertFalse(info.getDataNode().isDeleted());
    23         assertTrue(info.isInUserWorkSpace());
    24         //info.setDataNode(new FileNode(createFile("users/user1/components/deleted/c_123/description.xml"), true));
    25         info.setDataNode(new DisplayDataNode("test", true, createDescription(), false));
    26         assertFalse(info.isDeletable());
    27         assertTrue(info.isUndeletable());
    28         assertTrue(info.isEditable());
    29         assertTrue(info.getDataNode().isDeleted());
    30         assertTrue(info.isInUserWorkSpace());
    31         //info.setDataNode(new FileNode(createFile("components/c_123/description.xml"), false));
    32         info.setDataNode(new DisplayDataNode("test", false, createDescription(), true));
    33         assertTrue(info.isDeletable());
    34         assertFalse(info.isUndeletable());
    35         assertTrue(info.isEditable());
    36         assertFalse(info.isInUserWorkSpace());
    37         //info.setDataNode(new FileNode(createFile("components/c_123/"), false));
    38         info.setDataNode(new DisplayDataNode("test", false));
    39         assertFalse(info.isDeletable());
    40         assertFalse(info.isUndeletable());
    41         assertFalse(info.isEditable());
    42         //info.setDataNode(new FileNode(createFile("components/deleted/c_123/description.xml"), true));
    43         info.setDataNode(new DisplayDataNode("test", true, createDescription(), true));
    44         assertFalse(info.isDeletable());
    45         assertTrue(info.isUndeletable());
    46         assertTrue(info.isEditable());
    47         assertFalse(info.isInUserWorkSpace());
    48         assertTrue(info.getDescription().startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<profileDescription"));
    49         //info.setDataNode(new FileNode(createFile("components/deleted/c_123/"), true));
    50         info.setDataNode(new DisplayDataNode("test", true));
    51         assertFalse(info.isDeletable());
    52         assertFalse(info.isUndeletable());
    53         assertFalse(info.isEditable());
    54         assertEquals("", info.getDescription());
     17        CMDItemInfo info = new CMDItemInfo();
     18        //info.setDataNode(new FileNode(createFile("users/user1/components/c_123/description.xml"), false));
     19        info.setDataNode(new DisplayDataNode("test", false, createDescription(), ComponentStatus.DEVELOPMENT));
     20        assertTrue(info.isDeletable());
     21        assertFalse(info.isUndeletable());
     22        assertTrue(info.isEditable());
     23        assertFalse(info.getDataNode().isDeleted());
     24        assertEquals(ComponentStatus.DEVELOPMENT, info.getStatus());
     25        //info.setDataNode(new FileNode(createFile("users/user1/components/deleted/c_123/description.xml"), true));
     26        info.setDataNode(new DisplayDataNode("test", true, createDescription(), ComponentStatus.DEVELOPMENT));
     27        assertFalse(info.isDeletable());
     28        assertTrue(info.isUndeletable());
     29        assertTrue(info.isEditable());
     30        assertTrue(info.getDataNode().isDeleted());
     31        assertEquals(ComponentStatus.DEVELOPMENT, info.getStatus());
     32        //info.setDataNode(new FileNode(createFile("components/c_123/description.xml"), false));
     33        info.setDataNode(new DisplayDataNode("test", false, createDescription(), ComponentStatus.PUBLIC));
     34        assertTrue(info.isDeletable());
     35        assertFalse(info.isUndeletable());
     36        assertTrue(info.isEditable());
     37        assertEquals(ComponentStatus.PUBLIC, info.getStatus());
     38        //info.setDataNode(new FileNode(createFile("components/c_123/"), false));
     39        info.setDataNode(new DisplayDataNode("test", false));
     40        assertFalse(info.isDeletable());
     41        assertFalse(info.isUndeletable());
     42        assertFalse(info.isEditable());
     43        //info.setDataNode(new FileNode(createFile("components/deleted/c_123/description.xml"), true));
     44        info.setDataNode(new DisplayDataNode("test", true, createDescription(), ComponentStatus.PUBLIC));
     45        assertFalse(info.isDeletable());
     46        assertTrue(info.isUndeletable());
     47        assertTrue(info.isEditable());
     48        assertEquals(ComponentStatus.PUBLIC, info.getStatus());
     49        assertTrue(info.getDescription().startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<profileDescription"));
     50        //info.setDataNode(new FileNode(createFile("components/deleted/c_123/"), true));
     51        info.setDataNode(new DisplayDataNode("test", true));
     52        assertFalse(info.isDeletable());
     53        assertFalse(info.isUndeletable());
     54        assertFalse(info.isEditable());
     55        assertEquals("", info.getDescription());
    5556    }
    5657
    5758    private AbstractDescription createDescription() {
    58         return ProfileDescription.createNewDescription();
     59        return ProfileDescription.createNewDescription();
    5960    }
    60 
    6161}
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AdminRegistryTest.java

    r1603 r1993  
    1717import clarin.cmdi.componentregistry.ComponentRegistry;
    1818import clarin.cmdi.componentregistry.ComponentRegistryFactory;
     19import clarin.cmdi.componentregistry.ComponentStatus;
    1920import clarin.cmdi.componentregistry.DeleteFailedException;
    2021import clarin.cmdi.componentregistry.frontend.CMDItemInfo;
     
    2829@RunWith(SpringJUnit4ClassRunner.class)
    2930@ContextConfiguration(locations = {"/applicationContext.xml"})
    30 public class AdminRegistryTest  {
    31    
     31public class AdminRegistryTest {
     32
    3233    @Autowired
    3334    private ComponentDescriptionDao componentDescriptionDao;
     
    3738    private ComponentRegistryFactory componentRegistryFactory;
    3839    private static final Principal PRINCIPAL_ADMIN = DummyPrincipal.DUMMY_ADMIN_PRINCIPAL;
    39    
    4040    @Autowired
    4141    private JdbcTemplate jdbcTemplate;
    42    
     42
    4343    @Before
    4444    public void init() {
     
    4848    @Test
    4949    public void testForceUpdate() throws Exception {
    50         ComponentRegistry testRegistry = componentRegistryFactory.getPublicRegistry();
    51         String content1 = "";
    52         content1 += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    53         content1 += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    54         content1 += "    <Header/>\n";
    55         content1 += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
    56         content1 += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    57         content1 += "    </CMD_Component>\n";
    58         content1 += "</CMD_ComponentSpec>\n";
    59         ComponentDescription compDesc1 = RegistryTestHelper.addComponent(testRegistry, "XXX1", content1);
     50        ComponentRegistry testRegistry = componentRegistryFactory.getPublicRegistry();
     51        String content1 = "";
     52        content1 += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     53        content1 += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     54        content1 += "    <Header/>\n";
     55        content1 += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
     56        content1 += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
     57        content1 += "    </CMD_Component>\n";
     58        content1 += "</CMD_ComponentSpec>\n";
     59        ComponentDescription compDesc1 = RegistryTestHelper.addComponent(testRegistry, "XXX1", content1);
    6060
    61         String content2 = "";
    62         content2 += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    63         content2 += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    64         content2 += "    <Header/>\n";
    65         content2 += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    66         content2 += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    67         content2 += "        </CMD_Component>\n";
    68         content2 += "    </CMD_Component>\n";
    69         content2 += "</CMD_ComponentSpec>\n";
    70         ProfileDescription profileDesc = RegistryTestHelper.addProfile(testRegistry, "YYY1", content2);
     61        String content2 = "";
     62        content2 += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     63        content2 += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     64        content2 += "    <Header/>\n";
     65        content2 += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     66        content2 += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     67        content2 += "        </CMD_Component>\n";
     68        content2 += "    </CMD_Component>\n";
     69        content2 += "</CMD_ComponentSpec>\n";
     70        ProfileDescription profileDesc = RegistryTestHelper.addProfile(testRegistry, "YYY1", content2);
    7171
    72         AdminRegistry adminReg = new AdminRegistry();
    73         adminReg.setComponentRegistryFactory(componentRegistryFactory);
    74         adminReg.setComponentDescriptionDao(componentDescriptionDao);
    75         adminReg.setProfileDescriptionDao(profileDescriptionDao);
    76         CMDItemInfo fileInfo = new CMDItemInfo();
    77         fileInfo.setForceUpdate(false);
    78         fileInfo.setDataNode(new DisplayDataNode(compDesc1.getName(), false, compDesc1, true));
    79         fileInfo.setContent(content1);
    80         try {
    81             adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN);
    82             fail();
    83         } catch (SubmitFailedException e) {}
    84         fileInfo.setForceUpdate(true);
    85         adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); //Component needs to be forced because they can be used by other profiles/components
     72        AdminRegistry adminReg = new AdminRegistry();
     73        adminReg.setComponentRegistryFactory(componentRegistryFactory);
     74        adminReg.setComponentDescriptionDao(componentDescriptionDao);
     75        adminReg.setProfileDescriptionDao(profileDescriptionDao);
     76        CMDItemInfo fileInfo = new CMDItemInfo();
     77        fileInfo.setForceUpdate(false);
     78        fileInfo.setDataNode(new DisplayDataNode(compDesc1.getName(), false, compDesc1, ComponentStatus.PUBLIC));
     79        fileInfo.setContent(content1);
     80        try {
     81            adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN);
     82            fail();
     83        } catch (SubmitFailedException e) {
     84        }
     85        fileInfo.setForceUpdate(true);
     86        adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); //Component needs to be forced because they can be used by other profiles/components
    8687
    87         assertEquals(1, testRegistry.getComponentDescriptions().size());
    88         try {
    89             fileInfo.setForceUpdate(false);
    90             adminReg.delete(fileInfo, PRINCIPAL_ADMIN);
    91             fail();
    92         } catch (SubmitFailedException e) {
    93             assertTrue(e.getCause() instanceof DeleteFailedException);
    94         }
    95         assertEquals(1, testRegistry.getComponentDescriptions().size());
    96         fileInfo.setForceUpdate(true);
    97         adminReg.delete(fileInfo, PRINCIPAL_ADMIN);
    98         assertEquals(0, testRegistry.getComponentDescriptions().size());
     88        assertEquals(1, testRegistry.getComponentDescriptions().size());
     89        try {
     90            fileInfo.setForceUpdate(false);
     91            adminReg.delete(fileInfo, PRINCIPAL_ADMIN);
     92            fail();
     93        } catch (SubmitFailedException e) {
     94            assertTrue(e.getCause() instanceof DeleteFailedException);
     95        }
     96        assertEquals(1, testRegistry.getComponentDescriptions().size());
     97        fileInfo.setForceUpdate(true);
     98        adminReg.delete(fileInfo, PRINCIPAL_ADMIN);
     99        assertEquals(0, testRegistry.getComponentDescriptions().size());
    99100
    100         assertEquals(1, testRegistry.getProfileDescriptions().size());
    101         fileInfo.setForceUpdate(false);
    102         fileInfo.setDataNode(new DisplayDataNode(profileDesc.getName(), false, profileDesc, true));
    103         adminReg.delete(fileInfo, PRINCIPAL_ADMIN); //Profile do not need to be forced they cannot be used by other profiles
    104         assertEquals(0, testRegistry.getProfileDescriptions().size());
     101        assertEquals(1, testRegistry.getProfileDescriptions().size());
     102        fileInfo.setForceUpdate(false);
     103        fileInfo.setDataNode(new DisplayDataNode(profileDesc.getName(), false, profileDesc, ComponentStatus.PUBLIC));
     104        adminReg.delete(fileInfo, PRINCIPAL_ADMIN); //Profile do not need to be forced they cannot be used by other profiles
     105        assertEquals(0, testRegistry.getProfileDescriptions().size());
    105106    }
    106107}
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImplTest.java

    r1992 r1993  
    55import clarin.cmdi.componentregistry.model.RegistryUser;
    66import clarin.cmdi.componentregistry.ComponentRegistry;
     7import clarin.cmdi.componentregistry.ComponentStatus;
     8import clarin.cmdi.componentregistry.OwnerUser;
    79import clarin.cmdi.componentregistry.UserCredentials;
     10import clarin.cmdi.componentregistry.UserUnauthorizedException;
    811import clarin.cmdi.componentregistry.rest.DummyPrincipal;
    912import org.springframework.beans.factory.annotation.Autowired;
     
    5053
    5154    @Test
    52     public void getComponentRegistry() {
     55    public void getComponentRegistry() throws UserUnauthorizedException {
    5356        // Get public
    54         assertNotNull(componentRegistryFactory.getComponentRegistry(false, null));
     57        assertNotNull(componentRegistryFactory.getComponentRegistry(ComponentStatus.PUBLIC, null, null));
    5558
    5659        // Get for non-existing user
    5760        final RegistryUser testUser = UserDaoTest.createTestUser();
    58         UserCredentials credentials = new DummyPrincipal(testUser.
    59                 getPrincipalName()).getCredentials();
     61        UserCredentials credentials = new DummyPrincipal(testUser.getPrincipalName()).getCredentials();
    6062
    61         ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.
    62                 getComponentRegistry(true, credentials);
     63        ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials);
    6364        assertNotNull(cr1);
    6465        // Get for existing user
    65         ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.
    66                 getComponentRegistry(true, credentials);
     66        ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials);;
    6767        assertNotNull(cr2);
    6868        assertEquals(cr1.getOwner(), cr2.getOwner());
    6969
    7070        // Get for another new user
    71         UserCredentials credentials2 = new DummyPrincipal(testUser.
    72                 getPrincipalName() + "2").getCredentials();
    73         ComponentRegistryDbImpl cr3 = (ComponentRegistryDbImpl) componentRegistryFactory.
    74                 getComponentRegistry(true, credentials2);
     71        UserCredentials credentials2 = new DummyPrincipal(testUser.getPrincipalName() + "2").getCredentials();
     72        ComponentRegistryDbImpl cr3 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials2);
    7573        assertNotNull(cr3);
    7674        assertNotSame(cr1.getOwner(), cr3.getOwner());
     
    7876
    7977    @Test
    80     public void testGetOtherUserComponentRegistry() {
    81         UserCredentials userCredentials = DummyPrincipal.DUMMY_PRINCIPAL.
    82                 getCredentials();
     78    public void testGetOtherUserComponentRegistry() throws UserUnauthorizedException {
     79        UserCredentials userCredentials = DummyPrincipal.DUMMY_PRINCIPAL.getCredentials();
    8380
    8481        // Create registry for new user
    85         ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.
    86                 getComponentRegistry(true, userCredentials);
     82        ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, userCredentials);
    8783
    88         String id = cr1.getOwner().getId().toString();
     84        Number id = cr1.getOwner().getId();
    8985
    9086        // Get it as admin
    91         ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.
    92                 getOtherUserComponentRegistry(DummyPrincipal.DUMMY_ADMIN_PRINCIPAL, id);
     87        ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_ADMIN_PRINCIPAL, ComponentStatus.DEVELOPMENT, new OwnerUser(id));
    9388        assertNotNull(cr2);
    9489        // Should be this user's registry
     
    9792        // Try get it as non-admin
    9893        try {
    99             componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_PRINCIPAL, id);
     94            componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_PRINCIPAL, ComponentStatus.DEVELOPMENT, new OwnerUser(id));
    10095            fail("Non-admin can get other user's component registry");
    10196        } catch (Exception ex) {
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java

    r1916 r1993  
    33import clarin.cmdi.componentregistry.ComponentRegistry;
    44import clarin.cmdi.componentregistry.ComponentRegistryFactory;
     5import clarin.cmdi.componentregistry.ComponentStatus;
    56import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    67import clarin.cmdi.componentregistry.impl.database.ComponentRegistryBeanFactory;
     
    1617import com.sun.jersey.api.representation.Form;
    1718import com.sun.jersey.multipart.FormDataMultiPart;
     19import java.awt.image.ComponentSampleModel;
    1820import java.io.ByteArrayInputStream;
    1921import java.util.Date;
     
    689691    @Test
    690692    public void testRegisterWithUserComponents() throws Exception {
    691         ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry(true, DummyPrincipal.DUMMY_CREDENTIALS);
     693        ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, DummyPrincipal.DUMMY_CREDENTIALS);
    692694        String content = "";
    693695        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/MDValidatorTest.java

    r1816 r1993  
    33import clarin.cmdi.componentregistry.ComponentRegistry;
    44import clarin.cmdi.componentregistry.ComponentRegistryFactory;
     5import clarin.cmdi.componentregistry.ComponentStatus;
    56import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase;
    67import clarin.cmdi.componentregistry.model.ComponentDescription;
     
    164165        String id1 = "component1";
    165166        String id2 = "component2";
    166         ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry(true, DummyPrincipal.DUMMY_CREDENTIALS);
     167        ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, DummyPrincipal.DUMMY_CREDENTIALS);
    167168
    168169        String profileContent = "";
Note: See TracChangeset for help on using the changeset viewer.