Ignore:
Timestamp:
08/13/14 16:55:59 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Fixed issued arising after testing on localhost tomcat (completed)

File:
1 edited

Legend:

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

    r5550 r5552  
    8484    private GroupService groupService;
    8585
    86    
    8786    //
    8887    /**
    8988     * Default constructor, to use this as a (spring) bean. The public registry
    90      * by default. Use setRegistryStatus(), setRegistryOwner(), setGroupId() to make it another kind of
    91      * registry.
     89     * by default. Use setRegistryStatus(), setRegistryOwner(), setGroupId() to
     90     * make it another kind of registry.
    9291     *
    93      * 
     92     *
    9493     */
    9594    public ComponentRegistryDbImpl() throws TransformerException {
     
    9796    }
    9897
    99 
    10098    @Override
    10199    public Owner getRegistryOwner() {
    102100        return this.registryOwner;
    103101    }
    104    
     102
    105103    @Override
    106104    public void setRegistryOwner(Owner registryOwner) {
    107105        this.registryOwner = registryOwner;
    108106    }
    109    
    110    
     107
    111108    @Override
    112109    public RegistrySpace getRegistrySpace() {
     
    123120        return this.groupId;
    124121    }
    125    
     122
    126123    @Override
    127124    public void setGroupId(Number groupId) {
    128125        this.groupId = groupId;
    129126    }
    130    
    131     @Override
    132     public Number getBaseDescriptionOwnerId(String cmdId){
     127
     128    @Override
     129    public Number getBaseDescriptionOwnerId(String cmdId) {
    133130        BaseDescription bd = componentDao.getByCmdId(cmdId);
    134131        return bd.getDbUserId();
    135132    }
    136    
    137     @Override
    138     public  List<Number> getItemGroups(String cmdId){
     133
     134    @Override
     135    public List<Number> getItemGroups(String cmdId) {
    139136        List<Group> groups = groupService.getGroupsTheItemIsAMemberOf(cmdId);
    140137        List<Number> result = new ArrayList<Number>();
    141138        if (groups != null) {
    142             for (Group group: groups) {
     139            for (Group group : groups) {
    143140                result.add(group.getId());
    144141            }
     
    146143        return result;
    147144    }
    148    
     145
    149146    /**
    150147     * @return The user id, or null if there is no owner or it is not a user.
     
    157154        }
    158155    }
    159    
     156
    160157    @Override
    161158    public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException, UserUnauthorizedException {
     
    180177
    181178    @Override
    182     public Boolean isItemPublic(String id) throws ItemNotFoundException{
     179    public Boolean isItemPublic(String id) throws ItemNotFoundException {
    183180        BaseDescription desc = componentDao.getByCmdId(id);
    184181        if (desc == null) {
    185182            String idS = (id == null) ? "null" : id;
    186             throw new ItemNotFoundException("The component with the id " + idS+ "is not found in the database.");
     183            throw new ItemNotFoundException("The component with the id " + idS + "is not found in the database.");
    187184        }
    188185        return desc.isPublic();
     
    284281                    return comment;
    285282                } else {
    286                     throw new ComponentRegistryException("Comment " + commentId  + "for the profile "+profileId);
     283                    throw new ItemNotFoundException("Comment " + commentId + " for the profile " + profileId + " is not found.");
    287284                }
    288285            } catch (DataAccessException ex) {
     
    322319                    return comment;
    323320                } else {
    324                     throw new ComponentRegistryException("Comment " + commentId  + "for the profile "+componentId);
     321                    throw new ItemNotFoundException("Comment " + commentId + " for the component " + componentId + " is not found.");
    325322                }
    326323            } catch (DataAccessException ex) {
     
    437434    public int registerComment(Comment comment, String principalName) throws ComponentRegistryException, ItemNotFoundException, UserUnauthorizedException {
    438435        try {
    439             if (comment.getComponentId() != null)  {
    440                 if (this.canCurrentUserAccessDescription(comment.getComponentId()))
    441                 {
    442                 // Convert principal name to user record id
    443                 Number uid = convertUserIdInComment(comment, principalName);
    444                 // Set date to current date
    445                 comment.setCommentDate(new Date());
    446                 comment.setUserId(uid.longValue());
    447                 commentsDao.saveAndFlush(comment);
    448            
     436            if (comment.getComponentId() != null) {
     437                if (this.canCurrentUserAccessDescription(comment.getComponentId())) {
     438                    // Convert principal name to user record id
     439                    Number uid = convertUserIdInComment(comment, principalName);
     440                    // Set date to current date
     441                    comment.setCommentDate(new Date());
     442                    comment.setUserId(uid.longValue());
     443                    commentsDao.saveAndFlush(comment);
     444
     445                } else {
     446                    throw new UserUnauthorizedException("The logged-in user cannot access the component/profile with id " + comment.getComponentId());
     447                }
    449448            } else {
    450                 throw new UserUnauthorizedException("The logged-in user cannot access the component/profile with id "+comment.getComponentId());
    451             }
    452             } else {
    453                 throw new ComponentRegistryException("The component/profile id for this comment is null.");           
     449                throw new ComponentRegistryException("The component/profile id for this comment is null.");
    454450            }
    455451            return 0;
     
    623619    public void deleteMDComponent(String componentId, boolean forceDelete)
    624620            throws UserUnauthorizedException, DeleteFailedException, ComponentRegistryException, ItemNotFoundException {
    625         BaseDescription desc = componentDao.getByCmdId(componentId);
     621        BaseDescription desc = getComponentDescriptionAccessControlled(componentId);
    626622        if (desc != null) {
    627623            try {
     
    639635        }
    640636    }
    641 
    642    
    643637
    644638    private void invalidateCache(BaseDescription description) {
     
    704698
    705699    private void checkAuthorisation(BaseDescription desc) throws UserUnauthorizedException, ItemNotFoundException {
    706         if (!this.canCurrentUserAccessDescription(desc.getId())) {           
     700        if (!this.canCurrentUserAccessDescription(desc.getId())) {
    707701            String principalName = (registryOwner != null) ? userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName() : "null";
    708702            throw new UserUnauthorizedException("Unauthorized operation user '" + principalName
     
    715709        String principalName = userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName();
    716710        if (!(this.isOwnerOfComment(desc, principalName) || configuration.isAdminUser(principalName))) {
    717             throw new UserUnauthorizedException("Unauthorized operation user '" + principalName
    718                     + "' is not the creator (nor a member of the group, nor an administrator) of the " + (desc.getId()) + "(" + desc + ").");
     711            throw new UserUnauthorizedException("Unauthorized operation: user '" + principalName
     712                    + "' is not the creator (nor the Administrator) of the comment " + (desc.getId()));
    719713        }
    720714    }
     
    741735                throw new DeleteFailedException(
    742736                        "The "
    743                         + (desc.isProfile() ? "Profile" : "Component")
    744                         + " is more then a month old and cannot be deleted anymore. It might have been used to create metadata, deleting it would invalidate that metadata.");
     737                        + (desc.isProfile() ? "profile" : "Ccomponent")
     738                        + " is more than a month old and cannot be deleted anymore. It might have been used to create metadata, deleting it would invalidate that metadata.");
    745739            }
    746740        }
     
    766760    }
    767761
    768     private boolean canCurrentUserAccessDescription(String cmdId) throws ItemNotFoundException{
     762    private boolean canCurrentUserAccessDescription(String cmdId) throws ItemNotFoundException {
    769763        if (cmdId == null) {
    770764            throw new ItemNotFoundException("Item with the null cmdIdentifier.");
    771765        }
    772        
     766
    773767        BaseDescription description = componentDao.getByCmdId(cmdId);
    774768        if (description == null) {
    775             throw new ItemNotFoundException("Item with the id "+cmdId+" is not found.");
    776         }
    777        
    778        
     769            throw new ItemNotFoundException("Item with the id " + cmdId + " is not found.");
     770        }
     771
     772
    779773        Number userId = getUserId();
    780774        if (userId == null) {
     
    785779            return false;
    786780        }
    787        
     781
    788782
    789783        if (configuration.isAdminUser(user.getPrincipalName())) {
     
    805799
    806800    @Override
    807     public void deleteComment(String commentId) throws IOException, 
     801    public void deleteComment(String commentId) throws IOException,
    808802            UserUnauthorizedException, DeleteFailedException, ItemNotFoundException {
    809803        try {
     
    826820        }
    827821    }
    828    
    829  
    830822
    831823    @Override
     
    857849        for (String id : componentIds) {
    858850            BaseDescription description = componentDao.getByCmdId(id);
    859             components.add(ComponentUtils.toComponent(description));
     851            if (description != null) {
     852                components.add(ComponentUtils.toComponent(description));
     853            }
    860854        }
    861855        return components;
Note: See TracChangeset for help on using the changeset viewer.