Changeset 5661 for DASISH


Ignore:
Timestamp:
09/19/14 09:59:35 (10 years ago)
Author:
olhsha@mpi.nl
Message:

adding two html forms and two services for updating user-annotation access and public access of an annotation

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/CHANGES.txt

    r5401 r5661  
    4545Moreover, an atribute xml:id is added to the schema for main resource instances.
    4646
     47July 14, 2014. Added 1: api to send an image cached representation as a file, via its path
     48or URI. At least will help in testing because I have problems with turning an image file
     49onto a stream to send it via FF Client in a request body. Added 2: admin can change the external
     50ID (UUID) of a resource. At least will help with testing.
     51
     52
     53
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/UPDATE.txt

    r5401 r5661  
    1919This id is already set up in the jsp page, so no changes should be done there.
    2020
     214. Nothing is to be update in settings (web.xml, context.xml) and the database.
     22
    2123
    2224
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/pom.xml

    r5401 r5661  
    363363        <netbeans.hint.license>gpl20</netbeans.hint.license> 
    364364        <plugin.license.copyrightYear>2013</plugin.license.copyrightYear>
    365         <project.version>1.5</project.version>
     365        <project.version>1.5.1</project.version>
    366366        <shibboleth.version>1.0.4</shibboleth.version>
    367367    </properties>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java

    r5138 r5661  
    2525import java.sql.SQLException;
    2626import java.util.List;
     27import java.util.UUID;
    2728
    2829/**
     
    4041     */
    4142   
     43    public List<UUID> getExternalIdFromHeadline(String headline);
     44   
     45    public List<Number>  getInternalIDsFromHeadline(String headline);
    4246    /**
    4347     *
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBDispatcher.java

    r5468 r5661  
    394394
    395395    ResponseBody makeAccessResponseEnvelope(Number resourceID, Resource resource);
     396   
     397    UUID getPrincipalExternalIdFromName(String fullName) throws NotInDataBaseException;
     398   
     399    List<UUID> getAnnotationExternalIdsFromHeadline(String headline);
     400   
     401    List<Number> getAnnotationInternalIDsFromHeadline(String headline);
    396402}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/PrincipalDao.java

    r5385 r5661  
    5353     public UUID getPrincipalExternalIDFromRemoteID(String remoteID) throws NotInDataBaseException;
    5454     
     55     public UUID getExternalIdFromName(String fullName) throws NotInDataBaseException;
    5556     
    5657     public List<Number> getPrincipalIDsWithAccessForNotebook(Number notebookID, Access access);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBDispatcherImlp.java

    r5468 r5661  
    962962        }
    963963    }
     964   
     965    @Override
     966    public UUID getPrincipalExternalIdFromName(String fullName) throws NotInDataBaseException{
     967       return principalDao.getExternalIdFromName(fullName);
     968    }
     969   
     970    @Override
     971    public List<UUID> getAnnotationExternalIdsFromHeadline(String headline){
     972        return annotationDao.getExternalIdFromHeadline(headline);
     973    }
     974   
     975    @Override
     976    public List<Number> getAnnotationInternalIDsFromHeadline(String headline){
     977        return annotationDao.getInternalIDsFromHeadline(headline);
     978    }
    964979
    965980    //// privee ///
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r5393 r5661  
    110110        List<Access> result = this.loggedQuery(sql.toString(), public_RowMapper, annotationID);
    111111        return result.get(0);
     112    }
     113   
     114   
     115    @Override
     116    public List<UUID> getExternalIdFromHeadline(String headline){
     117        StringBuilder requestDB = new StringBuilder("SELECT ");
     118        requestDB.append(external_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append("'").append(headline).append("'").append("= ?");
     119        return this.loggedQuery(requestDB.toString(), externalIDRowMapper, headline);       
     120    }
     121   
     122    @Override
     123    public List<Number> getInternalIDsFromHeadline(String headline){
     124        StringBuilder requestDB = new StringBuilder("SELECT ");
     125        requestDB.append(annotation_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append("'").append(headline).append("'").append("= ?");
     126        return this.loggedQuery(requestDB.toString(), internalIDRowMapper, headline);       
    112127    }
    113128
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcPrincipalDao.java

    r5393 r5661  
    157157   
    158158    @Override
     159    public UUID getExternalIdFromName(String fullName) throws NotInDataBaseException {
     160        StringBuilder requestDB = new StringBuilder("SELECT ");
     161        requestDB.append(external_id).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_name).append("= ? LIMIT 1");
     162        List<UUID> result = this.loggedQuery(requestDB.toString(), externalIDRowMapper, fullName);
     163        if (result.isEmpty()) {
     164            throw new NotInDataBaseException("principal", "full name", fullName);
     165        }
     166        return result.get(0);
     167    }
     168   
     169    @Override
    159170    public String getTypeOfPrincipalAccount(Number internalID) {
    160171        StringBuilder requestDB = new StringBuilder("SELECT ");
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r5385 r5661  
    3434import java.util.Arrays;
    3535import java.util.HashMap;
     36import java.util.List;
    3637import java.util.Map;
    3738import java.util.UUID;
     
    4041import javax.ws.rs.Consumes;
    4142import javax.ws.rs.DELETE;
     43import javax.ws.rs.FormParam;
    4244import javax.ws.rs.GET;
    4345import javax.ws.rs.POST;
     
    6163@Transactional(rollbackFor = {Exception.class})
    6264public class AnnotationResource extends ResourceResource {
    63    
     65
    6466    public void setHttpServletResponse(HttpServletResponse httpServletResponse) {
    6567        this.httpServletResponse = httpServletResponse;
     
    210212    public JAXBElement<ResponseBody> createAnnotation(Annotation annotation) throws IOException {
    211213
    212             Map params = new HashMap();
    213             params.put("annotation", annotation);
    214             ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new AddAnnotation());
    215             if (result != null) {
    216                 return (new ObjectFactory()).createResponseBody(result);
    217             } else {
    218                 return (new ObjectFactory()).createResponseBody(new ResponseBody());
    219             }
    220         }
    221 
    222    
     214        Map params = new HashMap();
     215        params.put("annotation", annotation);
     216        ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new AddAnnotation());
     217        if (result != null) {
     218            return (new ObjectFactory()).createResponseBody(result);
     219        } else {
     220            return (new ObjectFactory()).createResponseBody(new ResponseBody());
     221        }
     222    }
    223223
    224224    private class AddAnnotation implements ILambda<Map, ResponseBody> {
     
    327327        }
    328328    }
     329   
     330    //////////////////////////////////////////
     331   
     332     //////////////////////////////////////////////
     333    @POST
     334    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     335    @Produces(MediaType.TEXT_PLAIN)
     336    @Path("publicaccessform")
     337    public String updatePubliAccessFromForm(
     338            @FormParam("annotationId") String annotationDatabaseId,
     339            @FormParam("annotationHeadline") String annotationHeadline,
     340            @FormParam("access") String access)
     341            throws IOException {
     342       
     343        if (access.trim().equals("")) {
     344            access = "none";
     345        }
     346       
     347        Access accessTyped = Access.fromValue(access);
     348        int updatedAnnotations = 0;
     349       
     350        if (annotationDatabaseId == null || annotationDatabaseId.trim().equals("")) {
     351            List<Number> annotationIDs = dbDispatcher.getAnnotationInternalIDsFromHeadline(annotationHeadline);
     352            if (annotationIDs == null || annotationIDs.isEmpty()) {
     353                return "No annotations with this headline have been found";
     354            };
     355            int count = 0;
     356            for (Number annotationID : annotationIDs) {
     357                count = dbDispatcher.updatePublicAttribute(annotationID, accessTyped);;
     358                updatedAnnotations = updatedAnnotations+count;
     359            }           
     360            return (updatedAnnotations + " row(s) are updated");
     361        } else {
     362            try {
     363            Number annotationID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(annotationDatabaseId), Resource.ANNOTATION);
     364            updatedAnnotations= dbDispatcher.updatePublicAttribute(annotationID, accessTyped);
     365            } catch (NotInDataBaseException e) {
     366              httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString());   
     367            }
     368        }
     369        return (updatedAnnotations + " annotation(s) are updated.");
     370    }
     371   
    329372    ////////////////////////////////////////////////////
    330373
     
    337380        return this.genericUpdateDeleteAccess(annotationExternalId, principalExternalId, access);
    338381    }
     382   
     383
     384
     385    //////////////////////////////////////////////
     386    @POST
     387    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     388    @Produces(MediaType.TEXT_PLAIN)
     389    @Path("permissionform")
     390    public String updatePermissionFromForm(@FormParam("login") String remoteID,
     391            @FormParam("fullName") String fullName,
     392            @FormParam("userId") String principalDatabaseId,
     393            @FormParam("annotationId") String annotationDatabaseId,
     394            @FormParam("annotationHeadline") String annotationHeadline,
     395            @FormParam("access") String access)
     396            throws IOException {
     397       
     398        if (access.trim().equals("")) {
     399            access = null;
     400        }
     401       
     402        try {
     403            if (principalDatabaseId == null || principalDatabaseId.trim().equals("")) {
     404                if (remoteID != null && !remoteID.trim().equals("")) {
     405                    principalDatabaseId = dbDispatcher.getPrincipalExternalIDFromRemoteID(remoteID).toString();
     406                } else {
     407                    if (fullName != null) {
     408                        principalDatabaseId = dbDispatcher.getPrincipalExternalIdFromName(fullName).toString();
     409                    } else {
     410                        httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "No user information is given");
     411                    }
     412                }
     413            }
     414        } catch (NotInDataBaseException e) {
     415            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString());
     416        }
     417
     418        if (annotationDatabaseId == null || annotationDatabaseId.trim().equals("")) {
     419            List<UUID> annotationIds = dbDispatcher.getAnnotationExternalIdsFromHeadline(annotationHeadline);
     420            if (annotationIds == null || annotationIds.isEmpty()) {
     421                return "No annotations with this headline found";
     422            };
     423            int count = 0;
     424            String tmp = null;
     425            for (UUID annotationId : annotationIds) {
     426                tmp = this.genericUpdateDeleteAccess(annotationId.toString(), principalDatabaseId, Access.fromValue(access));
     427                if (!tmp.startsWith("0")) {
     428                    count++;
     429                }
     430            }           
     431            return (count + " row(s) are updated");
     432        } else {
     433            return this.genericUpdateDeleteAccess(annotationDatabaseId, principalDatabaseId, Access.fromValue(access));
     434        }
     435    }
     436
    339437    ////////////////////////////////////////////
    340 
    341438    private String genericUpdateDeleteAccess(String annotationId, String principalId, Access access) throws IOException {
    342439        Map params = new HashMap();
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/index.jsp

    r5468 r5661  
    4040        <br>
    4141        <a href="api/authentication/logout"> logout</a> <br>
     42        <br>
    4243        <br>
     44        <a href="changePermissions.html"> Change access mode for a user and an annotation </a><br>
     45        <br>
     46        <br>
     47        <a href="publicAccess.html"> Change public access mode for an annotation </a> <br>
     48        <br>
    4349       
    4450        <b>Test URI-s</b><br>
Note: See TracChangeset for help on using the changeset viewer.