Changeset 4539


Ignore:
Timestamp:
02/20/14 15:52:16 (10 years ago)
Author:
olhsha
Message:

refactoring repetitive code for different sort of resources. Replaced with one code using enum type Resource

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java

    r4495 r4539  
    9393    public List<Number> retrieveTargetIDs(Number annotationID);   
    9494   
    95    
    96        /**
    97      *
    98      * @param annotationID
    99      * @return all the pairs (user-permission) for "annotationId" from the table annotations_principals permissions.
    100      */
    101     public List<Map<Number, String>>  getPermissions(Number annotationID);
    10295   
    10396    public Number  getOwner(Number annotationID);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java

    r4529 r4539  
    1818package eu.dasish.annotation.backend.dao;
    1919
     20import eu.dasish.annotation.backend.Resource;
    2021import eu.dasish.annotation.schema.Annotation;
    2122import eu.dasish.annotation.schema.AnnotationBody;
     
    2829import eu.dasish.annotation.schema.UserWithPermissionList;
    2930import eu.dasish.annotation.schema.ReferenceList;
     31import eu.dasish.annotation.schema.ResponseBody;
    3032import eu.dasish.annotation.schema.Target;
    3133import eu.dasish.annotation.schema.TargetInfo;
     
    4446public interface DBIntegrityService {
    4547
    46     public void setServiceURI(String serviceURI);
     48    void setServiceURI(String serviceURI);
     49   
    4750
    4851    /**
    4952     * GETTERS
    5053     */
    51     /**
    52      *
    53      * @param UUID
    54      * @return the internal identifier of the annotations with "externalID", or
    55      * null if no such annotation.
    56      */
    57     Number getAnnotationInternalIdentifier(UUID externalID);
    58 
    59     /**
    60      *
    61      * @param annotationID
    62      * @return the externalID of the annotation with "internalID" or null if
    63      * there is no such annotation.
    64      */
    65     UUID getAnnotationExternalIdentifier(Number annotationID);
    66 
    67     Number getAnnotationInternalIdentifierFromURI(String uri);
     54   
     55    Number getResourceInternalIdentifier(UUID externalID, Resource resource);
     56   
     57    Number getResourceInternalIdentifierFromURI(String uri, Resource resource);   
     58   
     59    UUID getResourceExternalIdentifier(Number resourceID, Resource resource);
     60   
     61    String getResourceURI(Number resourceID, Resource resource);
     62   
     63    UserWithPermissionList getPermissions(Number resourceID, Resource resource);
     64
    6865
    6966    /**
     
    10299    AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String access, String namespace, String after, String before);
    103100
    104     /**
    105      *
    106      * @param userID
    107      * @return the external identifier of the user "userID", or null if no such
    108      * user.
    109      */
    110     UUID getUserExternalIdentifier(Number userID);
    111 
    112     /**
    113      *
    114      * @param externalID
    115      * @return the internal identifier of the user with "externalID", or null if
    116      * there is no such user.
    117      */
    118     Number getUserInternalIdentifier(UUID externalID);
    119 
    120     /**
    121      *
    122      * @param cachedID
    123      * @return the external identifier of the cached representation "cachedID",
    124      * or null if no such one.
    125      */
    126     UUID getCachedRepresentationExternalIdentifier(Number cachedID);
    127 
    128     /**
    129      *
    130      * @param externalID
    131      * @return the internal identifier of the cachedRepresentation with
    132      * "externalID", or null if there is no such one.
    133      */
    134     Number getCachedRepresentationInternalIdentifier(UUID externalID);
    135 
    136     Number getTargetInternalIdentifier(UUID externalID);
    137 
    138     String getTargetURI(Number targetID);
    139 
    140     UUID getTargetExternalIdentifier(Number targetID);
    141 
    142     String getUserURI(Number userID);
     101   
    143102
    144103    /**
     
    181140    List<String> getUsersWithNoInfo(Number annotationID);
    182141
    183     /**
    184      *
    185      * @param annotationID
    186      * @return the list of TargetID's for which there is no cached
    187      * representation
    188      */
    189     public UserWithPermissionList getPermissionsForAnnotation(Number annotationID);
    190 
    191     /**
    192      *
    193      * @param TargetID
     142   
     143    /**
     144     *
     145     * @param targetID
    194146     * @return the list of the external version ID-s that refers to the same
    195147     * source (link) as targetID
    196148     */
    197     public ReferenceList getTargetsForTheSameLinkAs(Number targetID);
     149    ReferenceList getTargetsForTheSameLinkAs(Number targetID);
    198150
    199151    /**
     
    202154     * @return BLOB of the cachedID
    203155     */
    204     public InputStream getCachedRepresentationBlob(Number cachedID);
    205 
    206     public Target getTarget(Number internalID);
     156    InputStream getCachedRepresentationBlob(Number cachedID);
     157
     158    Target getTarget(Number internalID);
    207159
    208160    /**
     
    211163     * @return user with "userID"
    212164     */
    213     public User getUser(Number userID);
     165    User getUser(Number userID);
    214166
    215167    /**
     
    218170     * @return user with e-mail "eMail"
    219171     */
    220     public User getUserByInfo(String eMail);
    221 
    222     public String getUserRemoteID(Number internalID);
    223 
    224     public Number getUserInternalIDFromRemoteID(String remoteID);
     172    User getUserByInfo(String eMail);
     173
     174    String getUserRemoteID(Number internalID);
     175
     176    Number getUserInternalIDFromRemoteID(String remoteID);
    225177
    226178    /**
     
    231183     * permission is not given
    232184     */
    233     public Permission getPermission(Number annotationID, Number userID);
    234 
    235     public String getTypeOfUserAccount(Number userID);
    236 
    237     public boolean canRead(Number userID, Number annotationID);
    238 
    239     public boolean canWrite(Number userID, Number annotationID);
     185    Permission getPermission(Number annotationID, Number userID);
     186
     187    String getTypeOfUserAccount(Number userID);
     188
     189    boolean canRead(Number userID, Number annotationID);
     190
     191    boolean canWrite(Number userID, Number annotationID);
    240192
    241193    /// notebooks ///
    242194   
    243     public Number getNotebookInternalIdentifier(UUID externalIdentifier);
    244    
    245     public NotebookInfoList getNotebooks(Number prinipalID, String permission);
     195   
     196    NotebookInfoList getNotebooks(Number prinipalID, String permission);
    246197   
    247198    boolean hasAccess(Number notebookID, Number principalID, Permission permission);   
    248199   
    249     public ReferenceList getNotebooksOwnedBy(Number principalID);
    250 
    251     public ReferenceList getPrincipals(Number notebookID, String permission);
    252 
    253     public Notebook getNotebook(Number notebookID);
     200    ReferenceList getNotebooksOwnedBy(Number principalID);
     201
     202    ReferenceList getPrincipals(Number notebookID, String permission);
     203
     204    Notebook getNotebook(Number notebookID);
     205   
     206    Number getNotebookOwner(Number notebookID);
    254207
    255208    ReferenceList getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc);
     
    258211     * UPDATERS
    259212     */
    260     public boolean updateAccount(UUID userExternalID, String account);
     213    boolean updateAccount(UUID userExternalID, String account);
    261214
    262215    /**
     
    284237     * "annotationID".
    285238     */
    286     public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
     239    int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
    287240
    288241    /**
     
    293246     * annotations_principals_permissions
    294247     */
    295     public int updatePermissions(Number annotationID, UserWithPermissionList permissionList);
    296 
    297     public Number updateUser(User user);
     248    int updatePermissions(Number annotationID, UserWithPermissionList permissionList);
     249
     250    Number updateUser(User user);
    298251
    299252    /// notebooks ///
    300     public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo);
    301 
    302     public boolean addAnnotationToNotebook(Number notebookID, Number annotationID);
     253    boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo);
     254
     255    boolean addAnnotationToNotebook(Number notebookID, Number annotationID);
    303256
    304257    /**
     
    368321     * "annotationsPreincipalsPermissions"
    369322     */
    370     public int deleteUser(Number userID);
     323    int deleteUser(Number userID);
    371324
    372325    /**
     
    378331     * "annotationsPreincipalsPermissions"
    379332     */
    380     public int deleteUserSafe(Number userID);
     333    int deleteUserSafe(Number userID);
    381334
    382335    /**
     
    416369    boolean deleteNotebook(Number notebookID);
    417370   
     371   
     372    //////// HELPERS for resources /////
     373    ResponseBody makeAnnotationResponseEnvelope(Number annotationID);
     374   
     375    ResponseBody makeNotebookResponseEnvelope(Number notebookID);
     376   
     377    ResponseBody makePermissionResponseEnvelope(Number resourceID, Resource resource);
     378
     379   
    418380}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/ResourceDao.java

    r3865 r4539  
    1818package eu.dasish.annotation.backend.dao;
    1919
     20
     21import java.util.List;
     22import java.util.Map;
    2023import java.util.UUID;
    2124
     
    2932    public void setServiceURI(String serviceURI);
    3033   
    31      /**
    32      *
    33      * @param externalID
    34      * @return internal identifier of the reTarget with externalID, or null if there is no reTarget with this identifier
    35      */
     34   
    3635    public Number getInternalID(UUID externalId);
    3736   
    38    
    39      /**
    40      *
    41      * @param uri
    42      * @return internal identifier of the reTarget with uri, or null if there is no reTarget with this uri
    43      */
     37 
    4438    public Number getInternalIDFromURI(String uri);
    4539   
    46     /**
    47      *
    48      * @param internalId
    49      * @return the UUID (external ID) of the reTarget with the "internalID".
    50      */
     40 
    5141    public UUID getExternalID(Number internalId);
    5242   
    53     /**
    54      *
    55      * @param externalID
    56      * @return returns the URI which is a concatenation of the serviceURI and externalID
    57      */
     43 
    5844    public String externalIDtoURI(String externalID);
    5945   
     
    7157     */
    7258    public String getURIFromInternalID(Number internalID);
     59   
     60    public List<Map<Number, String>>  getPermissions(Number resourceID);
    7361}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4529 r4539  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.Resource;
    2021import eu.dasish.annotation.backend.Helpers;
    2122import eu.dasish.annotation.backend.dao.AnnotationDao;
     
    2324import eu.dasish.annotation.backend.dao.DBIntegrityService;
    2425import eu.dasish.annotation.backend.dao.NotebookDao;
     26import eu.dasish.annotation.backend.dao.ResourceDao;
    2527import eu.dasish.annotation.backend.dao.TargetDao;
    2628import eu.dasish.annotation.backend.dao.UserDao;
    2729import eu.dasish.annotation.backend.rest.AnnotationResource;
     30import eu.dasish.annotation.schema.Action;
     31import eu.dasish.annotation.schema.ActionList;
    2832import eu.dasish.annotation.schema.Annotation;
     33import eu.dasish.annotation.schema.AnnotationActionName;
    2934import eu.dasish.annotation.schema.AnnotationBody;
    3035import eu.dasish.annotation.schema.AnnotationInfo;
     
    3843import eu.dasish.annotation.schema.TargetInfoList;
    3944import eu.dasish.annotation.schema.Permission;
     45import eu.dasish.annotation.schema.PermissionActionName;
    4046import eu.dasish.annotation.schema.UserWithPermissionList;
    4147import eu.dasish.annotation.schema.ReferenceList;
     48import eu.dasish.annotation.schema.ResponseBody;
    4249import eu.dasish.annotation.schema.Target;
    4350import eu.dasish.annotation.schema.TargetInfo;
     
    5158import java.util.Map;
    5259import java.util.UUID;
     60import java.lang.reflect.Field;
    5361import org.springframework.beans.factory.annotation.Autowired;
    5462import org.slf4j.Logger;
     
    7381    final static protected String admin = "admin";
    7482    private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class);
     83
    7584    //////////////////////////////////
     85    private ResourceDao getDao(Resource resource) {
     86        switch (resource) {
     87            case PRINCIPAL:
     88                return userDao;
     89            case ANNOTATION:
     90                return annotationDao;
     91            case TARGET:
     92                return targetDao;
     93            case CACHED_REPRESENTATION:
     94                return cachedRepresentationDao;
     95            case NOTEBOOK:
     96                return notebookDao;
     97            default:
     98                return null;
     99        }
     100    }
    76101
    77102    @Override
     
    81106        targetDao.setServiceURI(serviceURI + "targets/");
    82107        annotationDao.setServiceURI(serviceURI + "annotations/");
    83         //notebookDao.setServiceURI(serviceURI+"notebooks/");
     108        notebookDao.setServiceURI(serviceURI + "notebooks/");
    84109    }
    85110
    86111    ///////////// GETTERS //////////////////////////
    87112    @Override
    88     public Number getAnnotationInternalIdentifier(UUID externalID) {
    89         return annotationDao.getInternalID(externalID);
    90     }
    91 
    92     @Override
    93     public Number getAnnotationInternalIdentifierFromURI(String uri) {
    94         return annotationDao.getInternalIDFromURI(uri);
    95     }
    96 
    97     @Override
    98     public UUID getAnnotationExternalIdentifier(Number annotationID) {
    99         return annotationDao.getExternalID(annotationID);
    100     }
    101 
    102     @Override
    103     public Number getTargetInternalIdentifier(UUID externalID) {
    104         return targetDao.getInternalID(externalID);
    105     }
    106 
    107     @Override
    108     public UUID getTargetExternalIdentifier(Number targetID) {
    109         return targetDao.getExternalID(targetID);
    110     }
    111 
    112     @Override
    113     public String getTargetURI(Number targetID) {
    114         return targetDao.getURIFromInternalID(targetID);
    115     }
    116 
    117     @Override
    118     public String getUserURI(Number userID) {
    119         return userDao.getURIFromInternalID(userID);
    120     }
    121 
    122     @Override
    123     public Number getUserInternalIdentifier(UUID externalID) {
    124         return userDao.getInternalID(externalID);
    125     }
    126 
    127     @Override
    128     public UUID getUserExternalIdentifier(Number userID) {
    129         return userDao.getExternalID(userID);
    130     }
    131 
    132     @Override
    133     public Number getCachedRepresentationInternalIdentifier(UUID externalID) {
    134         return cachedRepresentationDao.getInternalID(externalID);
    135     }
    136 
    137     @Override
    138     public UUID getCachedRepresentationExternalIdentifier(Number cachedID) {
    139         return cachedRepresentationDao.getExternalID(cachedID);
     113    public Number getResourceInternalIdentifier(UUID externalID, Resource resource) {
     114        return this.getDao(resource).getInternalID(externalID);
     115    }
     116
     117    @Override
     118    public Number getResourceInternalIdentifierFromURI(String uri, Resource resource) {
     119        return this.getDao(resource).getInternalIDFromURI(uri);
     120    }
     121
     122    @Override
     123    public UUID getResourceExternalIdentifier(Number resourceID, Resource resource) {
     124        return this.getDao(resource).getExternalID(resourceID);
     125    }
     126
     127    @Override
     128    public String getResourceURI(Number resourceID, Resource resource) {
     129        return this.getDao(resource).getURIFromInternalID(resourceID);
    140130    }
    141131
     
    153143            result.setTargets(sis);
    154144
    155             result.setPermissions(this.getPermissionsForAnnotation(annotationID));
     145            result.setPermissions(this.getPermissions(annotationID, Resource.ANNOTATION));
    156146            return result;
    157147        } else {
     
    168158    // TODO UNIT tests
    169159    @Override
    170     public UserWithPermissionList getPermissionsForAnnotation(Number annotationID) {
    171         if (annotationID != null) {
    172             List<Map<Number, String>> principalsPermissions = annotationDao.getPermissions(annotationID);
     160    public UserWithPermissionList getPermissions(Number resourceID, Resource resource) {
     161        if (resourceID != null) {
     162            List<Map<Number, String>> principalsPermissions = this.getDao(resource).getPermissions(resourceID);
    173163            UserWithPermissionList result = new UserWithPermissionList();
    174164            List<UserWithPermission> list = result.getUserWithPermission();
    175165            for (Map<Number, String> principalPermission : principalsPermissions) {
    176 
    177166                Number[] principal = new Number[1];
    178167                principalPermission.keySet().toArray(principal);
    179 
    180168                UserWithPermission userWithPermission = new UserWithPermission();
    181169                userWithPermission.setRef(userDao.getURIFromInternalID(principal[0]));
    182170                userWithPermission.setPermission(Permission.fromValue(principalPermission.get(principal[0])));
    183 
    184171                list.add(userWithPermission);
    185172            }
    186173            return result;
    187         } else {
    188             return null;
    189         }
    190 
    191     }
    192 
    193     ////////////////////////////////////////////////////////////////////////
     174
     175        }
     176        return null;
     177    }
     178
     179////////////////////////////////////////////////////////////////////////
    194180    @Override
    195181    public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String access, String namespace, String after, String before) {
     
    436422    }
    437423
    438     /// notebooks ///
    439     @Override
    440      public Number getNotebookInternalIdentifier(UUID externalIdentifier){
    441         return notebookDao.getInternalID(externalIdentifier);
    442     }
    443    
    444    
    445424    @Override
    446425    public NotebookInfoList getNotebooks(Number principalID, String permission) {
     
    471450
    472451    @Override
    473     public boolean hasAccess(Number notebookID, Number principalID, Permission permission){
     452    public boolean hasAccess(Number notebookID, Number principalID, Permission permission) {
    474453        List<Number> notebookIDs = notebookDao.getNotebookIDs(principalID, permission);
    475454        if (notebookIDs == null) {
    476455            return false;
    477         } 
     456        }
    478457        return notebookIDs.contains(notebookID);
    479458    }
    480    
    481    
     459
    482460    @Override
    483461    public ReferenceList getNotebooksOwnedBy(Number principalID) {
     
    530508            }
    531509        }
    532 
    533510        result.setPermissions(ups);
    534511        return result;
     512    }
     513
     514    @Override
     515    public Number getNotebookOwner(Number notebookID) {
     516        return notebookDao.getOwner(notebookID);
    535517    }
    536518
     
    781763
    782764////////////// HELPERS ////////////////////
     765    ////////////////////////////////////////
     766    @Override
     767    public ResponseBody makeAnnotationResponseEnvelope(Number annotationID) {
     768        ResponseBody result = new ResponseBody();
     769        Annotation annotation = this.getAnnotation(annotationID);
     770        result.setAnnotation(annotation);
     771        List<String> targetsNoCached = this.getTargetsWithNoCachedRepresentation(annotationID);
     772        ActionList actionList = new ActionList();
     773        result.setActionList(actionList);
     774        actionList.getAction().addAll(makeActionList(targetsNoCached, AnnotationActionName.CREATE_CACHED_REPRESENTATION.value()));
     775        return result;
     776    }
     777
     778    @Override
     779    public ResponseBody makeNotebookResponseEnvelope(Number notebookID) {
     780        ResponseBody result = new ResponseBody();
     781        result.setPermissions(null);
     782        Notebook notebook = this.getNotebook(notebookID);
     783        result.setNotebook(notebook);
     784        return result;
     785    }
     786
     787    @Override
     788    public ResponseBody makePermissionResponseEnvelope(Number resourceID, Resource resource) {
     789        ResponseBody result = new ResponseBody();
     790        UserWithPermissionList permissions = this.getPermissions(resourceID, resource);
     791        result.setPermissions(permissions);
     792        List<String> usersWithNoInfo = this.getUsersWithNoInfo(resourceID);
     793        ActionList actionList = new ActionList();
     794        result.setActionList(actionList);
     795        actionList.getAction().addAll(makeActionList(usersWithNoInfo, PermissionActionName.PROVIDE_USER_INFO.value()));
     796        return result;
     797    }
     798
     799    private List<Action> makeActionList(List<String> resourceURIs, String message) {
     800        if (resourceURIs != null) {
     801            if (resourceURIs.isEmpty()) {
     802                return (new ArrayList<Action>());
     803            } else {
     804                List<Action> result = new ArrayList<Action>();
     805                for (String resourceURI : resourceURIs) {
     806                    Action action = new Action();
     807                    result.add(action);
     808                    action.setMessage(message);
     809                    action.setObject(resourceURI);
     810                }
     811                return result;
     812            }
     813        } else {
     814            return null;
     815        }
     816    }
     817
     818    //// priveee ///
    783819    private Target createFreshTarget(TargetInfo targetInfo) {
    784820        Target target = new Target();
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r4521 r4539  
    2626import eu.dasish.annotation.schema.AnnotationInfo;
    2727import eu.dasish.annotation.schema.Permission;
     28import eu.dasish.annotation.schema.UserWithPermission;
     29import eu.dasish.annotation.schema.UserWithPermissionList;
    2830import java.lang.String;
    2931import java.sql.ResultSet;
     
    7678    ///////////////////////////////////////////////////////////////////
    7779    @Override
    78     public List<Map<Number, String>> getPermissions(Number annotationID) {
     80    public List<Map<Number, String>>  getPermissions(Number annotationID) {
    7981        if (annotationID == null) {
    8082            loggerAnnotationDao.debug(nullArgument);
     
    8587        return getSimpleJdbcTemplate().query(sql.toString(), principalsPermissionsRowMapper, annotationID);
    8688    }
    87     private final RowMapper<Map<Number, String>> principalsPermissionsRowMapper = new RowMapper<Map<Number, String>>() {
    88         @Override
    89         public Map<Number, String> mapRow(ResultSet rs, int rowNumber) throws SQLException {
    90             Map<Number, String> result = new HashMap<Number, String>();
    91             result.put(rs.getInt(principal_id), rs.getString(permission));
    92             return result;
    93         }
    94     };
    95 
     89   
     90   
    9691    @Override
    9792    public Permission getPermission(Number annotationID, Number userID) {
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r4529 r4539  
    6969    }
    7070   
    71  
     71    //////////////////////////////////////////////////
     72    @Override
     73    public List<Map<Number, String>>  getPermissions(Number notebookID) {
     74        if (notebookID == null) {
     75            loggerNotebookDao.debug(nullArgument);
     76            return null;
     77        }
     78        StringBuilder sql = new StringBuilder("SELECT ");
     79        sql.append(principal_id).append(",").append(permission).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE ").append(notebook_id).append("  = ?");
     80        return getSimpleJdbcTemplate().query(sql.toString(), principalsPermissionsRowMapper, notebookID);
     81    }
     82   
     83  /////////////
    7284
    7385    @Override
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r4506 r4539  
    2121import java.sql.ResultSet;
    2222import java.sql.SQLException;
     23import java.util.ArrayList;
     24import java.util.HashMap;
    2325import java.util.List;
     26import java.util.Map;
    2427import java.util.UUID;
    2528import javax.xml.datatype.DatatypeConfigurationException;
     
    151154        return externalIDtoURI(getExternalID(internalID).toString());
    152155    }
     156   
     157    // override for notebooks and annotations
     158    @Override
     159    public List<Map<Number, String>>  getPermissions(Number resourceID) {
     160       return (new ArrayList<Map<Number, String>>());
     161    }
    153162
    154163    /////////////////////////////////////////////////////
     
    220229    };
    221230
     231    protected final RowMapper<Map<Number, String>> principalsPermissionsRowMapper = new RowMapper<Map<Number, String>>() {
     232        @Override
     233        public Map<Number, String> mapRow(ResultSet rs, int rowNumber) throws SQLException {
     234            Map<Number, String> result = new HashMap<Number, String>();
     235            result.put(rs.getInt(principal_id), rs.getString(permission));
     236            return result;
     237        }
     238    };
     239   
     240    ////// END ROW MAPPERS /////
    222241    @Override
    223242    public String externalIDtoURI(String externalID) {
     
    270289
    271290    }
     291   
     292   
    272293}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r4532 r4539  
    1919
    2020import eu.dasish.annotation.backend.BackendConstants;
     21import eu.dasish.annotation.backend.Resource;
    2122import eu.dasish.annotation.backend.dao.DBIntegrityService;
    2223import eu.dasish.annotation.schema.Annotation;
    23 import eu.dasish.annotation.schema.AnnotationActionName;
     24import eu.dasish.annotation.schema.AnnotationBody;
    2425import eu.dasish.annotation.schema.AnnotationInfoList;
    25 import eu.dasish.annotation.schema.Action;
    26 import eu.dasish.annotation.schema.ActionList;
    27 import eu.dasish.annotation.schema.AnnotationBody;
    2826import eu.dasish.annotation.schema.ObjectFactory;
    2927import eu.dasish.annotation.schema.Permission;
    30 import eu.dasish.annotation.schema.PermissionActionName;
    3128import eu.dasish.annotation.schema.UserWithPermissionList;
    3229import eu.dasish.annotation.schema.ReferenceList;
    3330import eu.dasish.annotation.schema.ResponseBody;
    34 import eu.dasish.annotation.schema.UserWithPermission;
    3531import java.io.IOException;
    36 import java.net.URI;
    37 import java.sql.Timestamp;
    38 import java.util.ArrayList;
    39 import java.util.List;
    4032import java.util.UUID;
    4133import javax.servlet.ServletContext;
     
    113105        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    114106        try {
    115             final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     107            final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION);
    116108            if (annotationID != null) {
    117109                String remoteUser = httpServletRequest.getRemoteUser();
     
    144136        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    145137        try {
    146             final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     138            final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION);
    147139            if (annotationID != null) {
    148140                String remoteUser = httpServletRequest.getRemoteUser();
     
    157149                } else {
    158150                    verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser);
    159 
    160151                }
    161152            } else {
     
    209200        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    210201        try {
    211             final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     202            final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION);
    212203            String remoteUser = httpServletRequest.getRemoteUser();
    213204            Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     
    215206                if (annotationID != null) {
    216207                    if (dbIntegrityService.canRead(userID, annotationID)) {
    217                         final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID);
     208                        final UserWithPermissionList permissionList = dbIntegrityService.getPermissions(annotationID, Resource.ANNOTATION);
    218209                        return new ObjectFactory().createPermissionList(permissionList);
    219210                    } else {
     
    240231        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    241232        try {
    242             final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     233            final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION);
    243234            String remoteUser = httpServletRequest.getRemoteUser();
    244235            Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     
    280271        if (userID != null) {
    281272            Number annotationID = dbIntegrityService.addUsersAnnotation(userID, annotation);
    282             return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
     273            return new ObjectFactory().createResponseBody(dbIntegrityService.makeAnnotationResponseEnvelope(annotationID));
    283274        } else {
    284275            verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser);
     
    306297
    307298        try {
    308             final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     299            final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION);
    309300            if (annotationID != null) {
    310301                String remoteUser = httpServletRequest.getRemoteUser();
     
    313304                    if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(userID).equals(admin)) {
    314305                        int updatedRows = dbIntegrityService.updateAnnotation(annotation);
    315                         return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
     306                        return new ObjectFactory().createResponseBody(dbIntegrityService.makeAnnotationResponseEnvelope(annotationID));
    316307                    } else {
    317308                        verboseOutput.FORBIDDEN_PERMISSION_CHANGING(externalIdentifier);
     
    338329        dbIntegrityService.setServiceURI(path);
    339330        try {
    340             final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     331            final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION);
    341332            String remoteUser = httpServletRequest.getRemoteUser();
    342333            Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     
    345336                    if (dbIntegrityService.canWrite(userID, annotationID)) {
    346337                        int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody);
    347                         return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
     338                        return new ObjectFactory().createResponseBody(dbIntegrityService.makeAnnotationResponseEnvelope(annotationID));
    348339                    } else {
    349340                        verboseOutput.FORBIDDEN_ANNOTATION_WRITING(externalIdentifier);
     
    373364        if (remoteUserID != null) {
    374365            try {
    375                 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId));
     366                final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(userExternalId), Resource.PRINCIPAL);
    376367                if (userID != null) {
    377368                    try {
    378                         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
     369                        final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationExternalId), Resource.ANNOTATION);
    379370                        if (annotationID != null) {
    380371                            if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
     
    414405        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    415406        try {
    416             final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
     407            final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationExternalId), Resource.ANNOTATION);
    417408            String remoteUser = httpServletRequest.getRemoteUser();
    418409            Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     
    421412                    if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    422413                        int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions);
    423                         return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
     414                        return new ObjectFactory().createResponseBody(dbIntegrityService.makePermissionResponseEnvelope(annotationID, Resource.ANNOTATION));
    424415                    } else {
    425416                        verboseOutput.FORBIDDEN_PERMISSION_CHANGING(annotationExternalId);
     
    448439        int deletedRows = 0;
    449440        try {
    450             final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationId));
     441            final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationId), Resource.ANNOTATION);
    451442            String remoteUser = httpServletRequest.getRemoteUser();
    452443            Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     
    454445                if (annotationID != null) {
    455446                    if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    456                         Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userId));
     447                        Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(userId), Resource.PRINCIPAL);
    457448                        if (userID != null) {
    458449                            deletedRows = dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, null);
     
    477468        return (deletedRows + " is deleted.");
    478469    }
    479 /////////////////////////////////////////
    480 
    481     private ResponseBody makeAnnotationResponseEnvelope(Number annotationID) {
    482         ResponseBody result = new ResponseBody();
    483         result.setPermissions(null);
    484         Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
    485         result.setAnnotation(annotation);
    486         List<String> targetsNoCached = dbIntegrityService.getTargetsWithNoCachedRepresentation(annotationID);
    487         ActionList actionList = new ActionList();
    488         result.setActionList(actionList);
    489         actionList.getAction().addAll(makeActionList(targetsNoCached, AnnotationActionName.CREATE_CACHED_REPRESENTATION.value()));
    490         return result;
    491     }
    492 
    493     /////////////////////////////////////////
    494     private ResponseBody makePermissionResponseEnvelope(Number annotationID) {
    495         ResponseBody result = new ResponseBody();
    496         result.setAnnotation(null);
    497         UserWithPermissionList permissions = dbIntegrityService.getPermissionsForAnnotation(annotationID);
    498         result.setPermissions(permissions);
    499         List<String> usersWithNoInfo = dbIntegrityService.getUsersWithNoInfo(annotationID);
    500         ActionList actionList = new ActionList();
    501         result.setActionList(actionList);
    502         actionList.getAction().addAll(makeActionList(usersWithNoInfo, PermissionActionName.PROVIDE_USER_INFO.value()));
    503         return result;
    504     }
    505 
    506     // REFACTOR : move to the integrity service all te methods below 
    507     private List<Action> makeActionList(List<String> resourceURIs, String message) {
    508         if (resourceURIs != null) {
    509             if (resourceURIs.isEmpty()) {
    510                 return (new ArrayList<Action>());
    511             } else {
    512                 List<Action> result = new ArrayList<Action>();
    513                 for (String resourceURI : resourceURIs) {
    514                     Action action = new Action();
    515                     result.add(action);
    516                     action.setMessage(message);
    517                     action.setObject(resourceURI);
    518                 }
    519                 return result;
    520             }
    521         } else {
    522             return null;
    523         }
    524     }
     470
    525471}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java

    r4532 r4539  
    1919
    2020import eu.dasish.annotation.backend.BackendConstants;
     21import eu.dasish.annotation.backend.Resource;
    2122import eu.dasish.annotation.backend.dao.DBIntegrityService;
    2223import eu.dasish.annotation.schema.CachedRepresentationInfo;
     
    8384            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    8485            try {
    85                 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
     86                final Number cachedID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalId), Resource.CACHED_REPRESENTATION);
    8687                if (cachedID != null) {
    8788                    final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID);
     
    110111            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    111112            try {
    112                 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
     113                final Number cachedID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalId), Resource.CACHED_REPRESENTATION);
    113114                if (cachedID != null) {
    114115                    InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java

    r4532 r4539  
    1919
    2020import eu.dasish.annotation.backend.BackendConstants;
     21import eu.dasish.annotation.backend.Resource;
    2122import eu.dasish.annotation.backend.dao.DBIntegrityService;
    2223import eu.dasish.annotation.schema.Notebook;
     24import eu.dasish.annotation.schema.NotebookInfo;
    2325import eu.dasish.annotation.schema.NotebookInfoList;
    2426import eu.dasish.annotation.schema.ObjectFactory;
    2527import eu.dasish.annotation.schema.Permission;
    2628import eu.dasish.annotation.schema.ReferenceList;
     29import eu.dasish.annotation.schema.ResponseBody;
    2730import java.io.IOException;
    28 import java.net.URI;
    2931import java.sql.SQLException;
    3032import java.util.UUID;
    3133import javax.servlet.http.HttpServletRequest;
    3234import javax.servlet.http.HttpServletResponse;
     35import javax.ws.rs.Consumes;
    3336import javax.ws.rs.GET;
     37import javax.ws.rs.PUT;
    3438import javax.ws.rs.Path;
    3539import javax.ws.rs.PathParam;
     
    7074    private final Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class);
    7175    private final VerboseOutput verboseOutput = new VerboseOutput(httpServletResponse, loggerServer);
     76    private final String admin = "admin";
    7277
    7378    public NotebookResource() {
     
    126131        final Number principalID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    127132        if (principalID != null) {
    128             Number notebookID = dbIntegrityService.getNotebookInternalIdentifier(UUID.fromString(externalIdentifier));
     133            Number notebookID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK);
    129134            if (notebookID != null) {
    130135                if (dbIntegrityService.hasAccess(notebookID, principalID, Permission.fromValue("reader"))) {
     
    158163        final Number principalID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    159164        if (principalID != null) {
    160             Number notebookID = dbIntegrityService.getNotebookInternalIdentifier(UUID.fromString(externalIdentifier));
     165            Number notebookID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK);
    161166            if (notebookID != null) {
    162167                if (dbIntegrityService.hasAccess(notebookID, principalID, Permission.fromValue("reader"))) {
     
    190195        final Number principalID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    191196        if (principalID != null) {
    192             Number notebookID = dbIntegrityService.getNotebookInternalIdentifier(UUID.fromString(externalIdentifier));
     197            Number notebookID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK);
    193198            if (notebookID != null) {
    194199                if (dbIntegrityService.hasAccess(notebookID, principalID, Permission.fromValue("reader"))) {
     
    206211        return new ObjectFactory().createReferenceList(new ReferenceList());
    207212    }
     213
     214    @PUT
     215    @Consumes(MediaType.APPLICATION_XML)
     216    @Produces(MediaType.APPLICATION_XML)
     217    @Path("{notebookid: " + BackendConstants.regExpIdentifier + "}")
     218    public JAXBElement<ResponseBody> updateNotebookInfo(@PathParam("notebookid") String externalIdentifier, NotebookInfo notebookInfo) throws IOException {
     219        String path = uriInfo.getBaseUri().toString();
     220        dbIntegrityService.setServiceURI(path);
     221        String notebookURI = notebookInfo.getRef();
     222
     223        if (!(path + "notebook/" + externalIdentifier).equals(notebookURI)) {
     224            verboseOutput.IDENTIFIER_MISMATCH(externalIdentifier);
     225            return new ObjectFactory().createResponseBody(new ResponseBody());
     226        }
     227
     228        try {
     229            final Number notebookID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK);
     230            if (notebookID != null) {
     231                String remoteUser = httpServletRequest.getRemoteUser();
     232                Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     233                if (userID != null) {
     234                    if (userID.equals(dbIntegrityService.getNotebookOwner(notebookID)) || dbIntegrityService.getTypeOfUserAccount(userID).equals(admin)) {
     235                        boolean success = dbIntegrityService.updateNotebookMetadata(notebookID, notebookInfo);
     236                        if (success) {
     237                            return new ObjectFactory().createResponseBody(dbIntegrityService.makeNotebookResponseEnvelope(notebookID));
     238                        }
     239                    } else {
     240                        verboseOutput.FORBIDDEN_PERMISSION_CHANGING(externalIdentifier);
     241                        loggerServer.debug(" Ownership changing is the part of the full update of the notebook metadadata.");
     242                    }
     243                } else {
     244                    verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser);
     245                }
     246            } else {
     247                verboseOutput.NOTEBOOK_NOT_FOUND(externalIdentifier);
     248            }
     249        } catch (IllegalArgumentException e) {
     250            verboseOutput.ILLEGAL_UUID(externalIdentifier);
     251        }
     252        return new ObjectFactory().createResponseBody(new ResponseBody());
     253    }
     254   
     255   
     256   
    208257}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java

    r4532 r4539  
    2121import com.sun.jersey.multipart.MultiPart;
    2222import eu.dasish.annotation.backend.BackendConstants;
     23import eu.dasish.annotation.backend.Resource;
    2324import eu.dasish.annotation.backend.dao.DBIntegrityService;
    2425import eu.dasish.annotation.schema.CachedRepresentationInfo;
     
    9192            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    9293            try {
    93                 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(externalIdentifier));
     94                final Number targetID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.TARGET);
    9495                if (targetID != null) {
    9596                    final Target target = dbIntegrityService.getTarget(targetID);
     
    118119            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    119120            try {
    120                 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(externalIdentifier));
     121                final Number targetID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.TARGET);
    121122                if (targetID != null) {
    122123                    final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID);
     
    148149            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    149150            try {
    150                 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetIdentifier));
     151                final Number targetID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(targetIdentifier), Resource.TARGET);
    151152                if (targetID != null) {
    152153                    CachedRepresentationInfo metadata = multiPart.getBodyParts().get(0).getEntityAs(CachedRepresentationInfo.class);
     
    177178            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    178179            try {
    179                 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetExternalIdentifier));
    180                 if (targetID != null) {
    181                     final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedExternalIdentifier));
     180                final Number targetID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(targetExternalIdentifier), Resource.TARGET);
     181                if (targetID != null) {
     182                    final Number cachedID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(cachedExternalIdentifier), Resource.CACHED_REPRESENTATION);
    182183                    if (cachedID != null) {
    183184                        int[] resultDelete = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java

    r4532 r4539  
    1919
    2020import eu.dasish.annotation.backend.BackendConstants;
     21import eu.dasish.annotation.backend.Resource;
    2122import eu.dasish.annotation.backend.dao.DBIntegrityService;
    2223import eu.dasish.annotation.schema.CurrentUserInfo;
     
    8788            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    8889            try {
    89                 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
     90                final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.PRINCIPAL);
    9091                if (userID != null) {
    9192                    final User user = dbIntegrityService.getUser(userID);
     
    134135            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    135136            try {
    136                 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
     137                final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.PRINCIPAL);
    137138                if (userID != null) {
    138139                    final CurrentUserInfo userInfo = new CurrentUserInfo();
    139                     userInfo.setRef(dbIntegrityService.getUserURI(userID));
     140                    userInfo.setRef(dbIntegrityService.getResourceURI(userID, Resource.PRINCIPAL));
    140141                    userInfo.setCurrentUser(ifLoggedIn(userID));
    141142                    return new ObjectFactory().createCurrentUserInfo(userInfo);
     
    217218                final boolean updated = dbIntegrityService.updateAccount(UUID.fromString(externalId), accountType);
    218219                if (updated) {
    219                     return "The account was updated to "+dbIntegrityService.getTypeOfUserAccount(dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalId)));
     220                    return "The account was updated to "+dbIntegrityService.getTypeOfUserAccount(dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalId), Resource.PRINCIPAL));
    220221                } else {
    221222                   verboseOutput.ACCOUNT_IS_NOT_UPDATED();
     
    239240            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    240241                dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    241                 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
     242                final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.PRINCIPAL);
    242243                if (userID != null) {
    243244                    final Integer result = dbIntegrityService.deleteUser(userID);
     
    264265            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    265266                dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    266                 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
     267                final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.PRINCIPAL);
    267268                if (userID != null) {
    268269                    final Integer result = dbIntegrityService.deleteUserSafe(userID);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/VerboseOutput.java

    r4532 r4539  
    106106   
    107107    private MessageStatus _IDENTIFIER_MISMATCH(String identifier){
    108         return new MessageStatus("Wrong request: the annotation identifier   " + identifier + " and the annotation ID from the request body do not match.", HttpServletResponse.SC_BAD_REQUEST);
     108        return new MessageStatus("Wrong request: the annotation (notebook) identifier   " + identifier + " and the annotation (notebook) ID from the request body do not match.", HttpServletResponse.SC_BAD_REQUEST);
    109109    }
    110110   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java

    r4529 r4539  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.Resource;
    2021import eu.dasish.annotation.backend.TestBackendConstants;
    2122import eu.dasish.annotation.backend.TestInstances;
     
    100101    public void testGetAnnotationInternalIdentifier() {
    101102        System.out.println("getAnnotationInternalIdentifier");
    102         final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000021");
    103 
     103        final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000021");       
     104        //dbIntegrityService.setResourceList();
    104105        mockeryDao.checking(new Expectations() {
    105106            {
     
    108109            }
    109110        });
    110         assertEquals(1, dbIntegrityService.getAnnotationInternalIdentifier(externalID));
     111        assertEquals(1, dbIntegrityService.getResourceInternalIdentifier(externalID, Resource.ANNOTATION));
    111112    }
    112113
     
    126127            }
    127128        });
    128         assertEquals("00000000-0000-0000-0000-000000000021", dbIntegrityService.getAnnotationExternalIdentifier(1).toString());
     129        assertEquals("00000000-0000-0000-0000-000000000021", dbIntegrityService.getResourceExternalIdentifier(1, Resource.ANNOTATION).toString());
    129130    }
    130131
     
    145146            }
    146147        });
    147         assertEquals(1, dbIntegrityService.getUserInternalIdentifier(externalID));
     148        assertEquals(1, dbIntegrityService.getResourceInternalIdentifier(externalID, Resource.PRINCIPAL));
    148149    }
    149150
     
    163164            }
    164165        });
    165         assertEquals("00000000-0000-0000-0000-000000000111", dbIntegrityService.getUserExternalIdentifier(1).toString());
     166        assertEquals("00000000-0000-0000-0000-000000000111", dbIntegrityService.getResourceExternalIdentifier(1, Resource.PRINCIPAL).toString());
    166167    }
    167168
     
    843844        });
    844845
    845        assertEquals(1, dbIntegrityService.getNotebookInternalIdentifier(mockUUID));
     846       assertEquals(1, dbIntegrityService.getResourceInternalIdentifier(mockUUID, Resource.NOTEBOOK));
    846847   
    847848    } 
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r4529 r4539  
    1818package eu.dasish.annotation.backend.rest;
    1919
     20import eu.dasish.annotation.backend.Resource;
    2021import eu.dasish.annotation.backend.dao.DBIntegrityService;
    21 import eu.dasish.annotation.backend.MockObjectsFactoryRest;
    2222import eu.dasish.annotation.backend.TestBackendConstants;
    2323import eu.dasish.annotation.backend.TestInstances;
     24import eu.dasish.annotation.schema.Action;
     25import eu.dasish.annotation.schema.ActionList;
    2426import eu.dasish.annotation.schema.AnnotationBody;
    2527import eu.dasish.annotation.schema.AnnotationBody.TextBody;
     
    3032import eu.dasish.annotation.schema.ResponseBody;
    3133import eu.dasish.annotation.schema.AnnotationActionName;
    32 import eu.dasish.annotation.schema.Permission;
    3334import java.io.IOException;
    3435import java.sql.SQLException;
     
    8788     * Test of getAnnotation method, of class AnnotationResource.
    8889     */
     90   
     91   /*
     92   
     93    * public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String externalIdentifier) throws IOException {
     94        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     95        try {
     96            final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION);
     97            if (annotationID != null) {
     98                String remoteUser = httpServletRequest.getRemoteUser();
     99                final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     100                if (userID != null) {
     101                    if (dbIntegrityService.canRead(userID, annotationID)) {
     102                        final Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
     103                        return new ObjectFactory().createAnnotation(annotation);
     104                    } else {
     105                        verboseOutput.FORBIDDEN_ANNOTATION_READING(externalIdentifier);
     106                    }
     107                } else {
     108                    verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser);
     109                }
     110            } else {
     111                verboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier);
     112            }
     113        } catch (IllegalArgumentException e) {
     114            verboseOutput.ILLEGAL_UUID(externalIdentifier);
     115        }
     116        return new ObjectFactory().createAnnotation(new Annotation());
     117    }
     118    *
     119    */
     120   
    89121    @Test
    90122    public void testGetAnnotation() throws SQLException, JAXBException, Exception {
     
    103135               
    104136               
    105                 oneOf(mockDbIntegrityService).setServiceURI(with(any(String.class)));
     137                oneOf(mockDbIntegrityService).setServiceURI("http://localhost:8080/annotator-backend/api/");
    106138                will(doAll());
     139               
     140                oneOf(mockDbIntegrityService).getResourceInternalIdentifier(with(aNonNull(UUID.class)), with(aNonNull((Resource.class))));               
     141                will(returnValue(2));
    107142               
    108143                oneOf(mockDbIntegrityService).getUserInternalIDFromRemoteID("olhsha@mpi.nl");
     
    110145               
    111146                oneOf(mockDbIntegrityService).canRead(3, 2);
    112                 will(returnValue(true));
    113                
    114                 oneOf(mockDbIntegrityService).getAnnotationInternalIdentifier(with(any(UUID.class)));               
    115                 will(returnValue(2));
     147                will(returnValue(true)); 
    116148               
    117149                oneOf(mockDbIntegrityService).getAnnotation(2);               
     
    144176            { 
    145177               oneOf(mockUriInfo).getBaseUri();
    146                will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/")));
    147                
     178               will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/")));               
    148179             
    149180                oneOf(mockDbIntegrityService).getUserInternalIDFromRemoteID("olhsha@mpi.nl");
     
    153184                will(doAll());
    154185               
    155                 oneOf(mockDbIntegrityService).getAnnotationInternalIdentifier(with(aNonNull(UUID.class)));             
     186                oneOf(mockDbIntegrityService).getResourceInternalIdentifier(with(aNonNull(UUID.class)), with(aNonNull((Resource.class))));             
    156187                will(returnValue(4));
    157188               
     
    207238        addedAnnotation.setOwnerRef("http://localhost:8080/annotator-backend/api/users/"+"00000000-0000-0000-0000-000000000111");
    208239     
     240        final ResponseBody mockEnvelope = new ResponseBody();
     241        final Action action = new Action();
     242        final ActionList actionList = new ActionList();
     243        mockEnvelope.setAnnotation(addedAnnotation);
     244        mockEnvelope.setActionList(actionList);
     245        actionList.getAction().add(action);
     246        action.setMessage(AnnotationActionName.CREATE_CACHED_REPRESENTATION.value());
     247        action.setObject("http://localhost:8080/annotator-backend/api/targets/00000000-0000-0000-0000-000000000036");
     248               
    209249        annotationResource.setHttpServletRequest(mockRequest);
    210250        annotationResource.setUriInfo(mockUriInfo);
     
    221261                oneOf(mockDbIntegrityService).getUserInternalIDFromRemoteID("olhsha@mpi.nl");
    222262                will(returnValue(3));
    223                
    224              
     263                             
    225264                oneOf(mockDbIntegrityService).addUsersAnnotation(3, annotationToAdd);
    226265                will(returnValue(newAnnotationID));
     
    231270                oneOf(mockDbIntegrityService).getTargetsWithNoCachedRepresentation(newAnnotationID);
    232271                will(returnValue(targets));
     272               
     273                oneOf(mockDbIntegrityService).makeAnnotationResponseEnvelope(newAnnotationID);
     274                will(returnValue(mockEnvelope));
    233275               
    234276          }
Note: See TracChangeset for help on using the changeset viewer.