Changeset 4264


Ignore:
Timestamp:
01/15/14 13:13:21 (10 years ago)
Author:
olhsha
Message:

replacing "admin_rights" with the "account" in the principals table. A principal can be user, developer or admin. A developer or and admin have access to the debugging uri's. A debugging request GET all annotation infos is added.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main
Files:
10 edited

Legend:

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

    r4262 r4264  
    6868    public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String namespace, Timestamp after, Timestamp before);
    6969     
     70    public List<Number> getAllAnnotationIDs();
     71   
    7072       /**
    7173     * unit test is missing
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java

    r4262 r4264  
    8989    List<Number> getFilteredAnnotationIDs(String link, String text, Number inloggedUserID, String[] accessModes, String namespace, Timestamp after, Timestamp before);
    9090   
    91    
     91    AnnotationInfoList getAllAnnotationInfos();
    9292   
    9393    /**
     
    233233   
    234234   
    235     public boolean userHasAdminRights(Number userID);
     235    public String getTypeOfUserAccount(Number userID);
    236236   
    237237    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/UserDao.java

    r4260 r4264  
    3838     public boolean userExists(User user);
    3939     
    40      public boolean hasAdminRights(Number internalID);
     40     public String getTypeOfUserAccount(Number internalID);
    4141     
    4242     public String getRemoteID(Number internalID);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4263 r4264  
    275275            return null;
    276276        }
    277 
     277    }
     278
     279    @Override
     280    public AnnotationInfoList getAllAnnotationInfos() {
     281        List<Number> annotationIDs = annotationDao.getAllAnnotationIDs();
     282        if (annotationIDs != null) {
     283            AnnotationInfoList result = new AnnotationInfoList();
     284            for (Number annotationID : annotationIDs) {
     285                Number ownerID = annotationDao.getOwner(annotationID);               
     286                ReferenceList targets = getAnnotationTargets(annotationID);
     287                AnnotationInfo annotationInfo = annotationDao.getAnnotationInfoWithoutTargets(annotationID);
     288                annotationInfo.setTargets(targets);
     289                if (ownerID != null){
     290                annotationInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID));}
     291                else {
     292                   annotationInfo.setOwnerRef("ACHTUNG: This annotation does not have an owner in the DB!!!!");
     293                }
     294                result.getAnnotationInfo().add(annotationInfo);
     295            }
     296
     297            return result;
     298        } else {
     299            return null;
     300        }
    278301    }
    279302
     
    343366
    344367    @Override
    345     public boolean userHasAdminRights(Number userID) {
    346         return userDao.hasAdminRights(userID);
     368    public String getTypeOfUserAccount(Number userID) {
     369        return userDao.getTypeOfUserAccount(userID);
    347370    }
    348371
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r4262 r4264  
    180180
    181181        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params);
     182    }
     183   
     184    /////////////////////////////////////////
     185   
     186    @Override
     187    public List<Number> getAllAnnotationIDs(){
     188        StringBuilder sql = new StringBuilder("SELECT ");
     189        sql.append(annotation_id).append(" , ").append(last_modified).append(" FROM ").append(annotationTableName).append(" ORDER BY ").append(last_modified).append(" DESC");
     190        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper);       
    182191    }
    183192
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r4262 r4264  
    5050    final static protected String targetsCachedRepresentationsTableName = "targets_cached_representations";
    5151    // base string constants: field Names
    52     final static protected String admin_rights = "admin_rights";
     52    final static protected String account = "account";
    5353    final static protected String annotation_id = "annotation_id";
    5454    final static protected String notebook_id = "notebook_id";
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java

    r4262 r4264  
    132132   
    133133    @Override
    134     public boolean hasAdminRights(Number internalID){
     134    public String getTypeOfUserAccount(Number internalID){
    135135       StringBuilder requestDB  = new StringBuilder("SELECT ");
    136        requestDB.append(admin_rights).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1");
    137        List<Boolean> result = getSimpleJdbcTemplate().query(requestDB.toString(), adminRightsRowMapper, internalID);
    138        return  (result.size() > 0) ? result.get(0).booleanValue() :false;   
     136       requestDB.append(account).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1");
     137       List<String> result = getSimpleJdbcTemplate().query(requestDB.toString(), adminRightsRowMapper, internalID);
     138       return  (result.size() > 0) ? result.get(0) :null;   
    139139    }
    140      private final RowMapper<Boolean> adminRightsRowMapper = new RowMapper<Boolean>() {
     140     private final RowMapper<String> adminRightsRowMapper = new RowMapper<String>() {
    141141        @Override
    142         public Boolean mapRow(ResultSet rs, int rowNumber) throws SQLException {
    143             return new Boolean(rs.getBoolean(admin_rights));
     142        public String mapRow(ResultSet rs, int rowNumber) throws SQLException {
     143            return rs.getString(account);
    144144        }
    145145    };
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r4263 r4264  
    8181    private Providers providers;
    8282    final String default_permission = "reader";
    83     private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class);
     83    private final Logger logger = LoggerFactory.getLogger(AnnotationResource.class);
     84    private final String admin = "admin";
     85    private final String developer = "developer";
    8486
    8587    public void setUriInfo(UriInfo uriInfo) {
     
    100102
    101103    public AnnotationResource() {
     104    }
     105
     106    @GET
     107    @Produces(MediaType.TEXT_XML)
     108    @Path("/all/debug")
     109    @Transactional(readOnly = true)
     110    public JAXBElement<AnnotationInfoList> getAllAnnotations() throws IOException {
     111        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     112        Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
     113        if (userID != null) {
     114            String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID);
     115            if (typeOfAccount.equals(admin) || typeOfAccount.equals(developer)) {
     116                final AnnotationInfoList annotationInfoList = dbIntegrityService.getAllAnnotationInfos();
     117                return new ObjectFactory().createAnnotationInfoList(annotationInfoList);
     118            } else {
     119                httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged in user is neither developer nor admin, and therefore cannot perform this request.");
     120                return null;
     121            }
     122        } else {
     123            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database");
     124            return null;
     125        }
     126
    102127    }
    103128
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java

    r4262 r4264  
    6363    @Context
    6464    private UriInfo uriInfo;
    65 
     65   
     66    final private String admin = "admin";
     67   
    6668    public void setHttpRequest(HttpServletRequest request) {
    6769        this.httpServletRequest = request;
     
    145147        final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
    146148        if (remoteUserID != null) {
    147             if (dbIntegrityService.userHasAdminRights(remoteUserID)) {
     149            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    148150                dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    149151                final Number userID = dbIntegrityService.addUser(user, remoteId);
     
    172174        final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
    173175        if (remoteUserID != null) {
    174             if (dbIntegrityService.userHasAdminRights(remoteUserID)) {
     176            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    175177                dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    176178                final Number userID = dbIntegrityService.updateUser(user);
     
    197199        final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
    198200        if (remoteUserID != null) {
    199             if (dbIntegrityService.userHasAdminRights(remoteUserID)) {
     201            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    200202                dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    201203                final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
     
    223225        final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
    224226        if (remoteUserID != null) {
    225             if (dbIntegrityService.userHasAdminRights(remoteUserID)) {
     227            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    226228                dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    227229                final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/index.jsp

    r4245 r4264  
    5858     GET <a href="api/targets/00000000-0000-0000-0000-000000000032/versions">api/targets/00000000-0000-0000-0000-000000000032/versions</a>   <br>
    5959     GET <a href="api/cached/00000000-0000-0000-0000-000000000051/metadata">api/cached/00000000-0000-0000-0000-000000000051/metadata</a><br>
    60      GET <a href="api/cached/00000000-0000-0000-0000-000000000051/content">api/cached/00000000-0000-0000-0000-000000000051/content></a> !Problem: works only on image.jpeg, end maps png-blobs to jpegs.
    61     </body>
     60     GET <a href="api/cached/00000000-0000-0000-0000-000000000051/content">api/cached/00000000-0000-0000-0000-000000000051/content</a> !Problem: works only on image.jpeg, end maps png-blobs to jpegs.
     61     <br>
     62     <br>
     63      <b>Debugging URI's (only for developers)</b><br>
     64      GET <a href="api/annotations/all/debug">api/annotations/all/debug</a>
     65      </body>
    6266        </html>
Note: See TracChangeset for help on using the changeset viewer.