Ignore:
Timestamp:
May 1, 2011, 12:19:10 PM (13 years ago)
Author:
mlg
Message:

Adds support for method pwg.categories.delete
(allows to delete a category).

Location:
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CategoryDao.java

    r10505 r10714  
    2828     */
    2929    public boolean create(Category category) throws JiwigoException;
     30
     31    /**
     32     * Function that deletes a given category
     33     * @param category the category to delete
     34     * @return true if the category is successfully deleted
     35     * @throws JiwigoException
     36     */
     37    public boolean delete(Category category) throws JiwigoException;
    3038}
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CategoryDaoImpl.java

    r10505 r10714  
    111111    }
    112112
     113    /**
     114     * @see fr.mael.jiwigo.dao.CategoryDao#delete(fr.mael.jiwigo.om.Category)
     115     */
     116    public boolean delete(Category category) throws JiwigoException {
     117        //this document will allow to get pwg_token. it is necessary to delete a category
     118        Document docStatus = sessionManager.executeReturnDocument(MethodsEnum.SESSION_STATUS.getLabel());
     119        String pwgToken = Tools.getStringValueDom(docStatus.getDocumentElement(), "pwg_token");
     120        if (pwgToken.equals("")) {
     121            throw new JiwigoException("Error getting pwg_token. Returned document was : "
     122                    + Tools.documentToString(docStatus));
     123        }
     124        if (LOG.isDebugEnabled()) {
     125            LOG.debug("Deletes category " + category.getIdentifier() + " with pwg_token = " + pwgToken);
     126        }
     127
     128        Document doc = sessionManager.executeReturnDocument(MethodsEnum.DELETE_CATEGORY.getLabel(), "category_id",
     129                String.valueOf(category.getIdentifier()), "pwg_token", pwgToken);
     130
     131        if (LOG.isDebugEnabled()) {
     132            LOG.debug(Tools.documentToString(doc));
     133        }
     134        try {
     135            return Tools.checkOk(doc);
     136        } catch (FileAlreadyExistsException e) {
     137            e.printStackTrace();
     138        }
     139        return false;
     140    }
     141
    113142    public SessionManager getSessionManager() {
    114143        return sessionManager;
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/ImageDaoImpl.java

    r10704 r10714  
    146146        String thumbnailBase64 = base64.encode(Tools.getBytesFromFile(image.getThumbnail()));
    147147        //sends the thumbnail and gets the result
    148         Document reponseThumb = (sessionManager.executeReturnDocument("pwg.images.addChunk", "data", thumbnailBase64,
    149                 "type", "thumb", "position", "1", "original_sum",
     148        Document reponseThumb = (sessionManager.executeReturnDocument(MethodsEnum.ADD_CHUNK.getLabel(), "data",
     149                thumbnailBase64, "type", "thumb", "position", "1", "original_sum",
    150150                Tools.getMD5Checksum(image.getOriginale().getAbsolutePath())));
    151151
     
    160160            File fichierAEnvoyer = filesToSend.get(i);
    161161            String originaleBase64 = base64.encode(Tools.getBytesFromFile(fichierAEnvoyer));
    162             Document reponseOriginale = (sessionManager.executeReturnDocument("pwg.images.addChunk", "data",
     162            Document reponseOriginale = (sessionManager.executeReturnDocument(MethodsEnum.ADD_CHUNK.getLabel(), "data",
    163163                    originaleBase64, "type", "file", "position", String.valueOf(i), "original_sum",
    164164                    Tools.getMD5Checksum(image.getOriginale().getAbsolutePath())));
     
    171171
    172172        //add the image in the database and get the result of the webservice
    173         Document reponseAjout = (sessionManager.executeReturnDocument("pwg.images.add", "file_sum",
     173        Document reponseAjout = (sessionManager.executeReturnDocument(MethodsEnum.ADD_IMAGE.getLabel(), "file_sum",
    174174                Tools.getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum",
    175175                Tools.getMD5Checksum(image.getThumbnail().getCanonicalPath()), "position", "1", "original_sum",
     
    177177                String.valueOf(image.getIdCategory()), "name", image.getName(), "author", sessionManager.getLogin(),
    178178                "level", image.getPrivacyLevel()));
    179         LOG.debug("Response add : " + Tools.documentToString(reponseAjout));
     179        if (LOG.isDebugEnabled()) {
     180            LOG.debug("Response add : " + Tools.documentToString(reponseAjout));
     181        }
    180182        //      System.out.println(Main.sessionManager.executerReturnString("pwg.images.add", "file_sum", Outil
    181183        //              .getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Outil.getMD5Checksum(image
     
    294296            //                          string.lastIndexOf("}") + 1);
    295297            try {
    296                 multipartEntity.addPart("method", new StringBody("pwg.images.addSimple"));
     298                multipartEntity.addPart("method", new StringBody(MethodsEnum.ADD_SIMPLE.getLabel()));
    297299                multipartEntity.addPart("category", new StringBody(category.toString()));
    298300                multipartEntity.addPart("name", new StringBody(title));
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/TagDaoImpl.java

    r10700 r10714  
    5555    public List<Tag> list() throws JiwigoException {
    5656        Document doc = sessionManager.executeReturnDocument(MethodsEnum.TAGS_ADMIN_LIST.getLabel());
    57         //      System.out.println(Outil.documentToString(doc));
    58         NodeList nodeList = doc.getDocumentElement().getElementsByTagName("tags");
    5957        return getTagsFromDocument((Element) doc.getDocumentElement().getElementsByTagName("tags").item(0));
    6058
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CategoryService.java

    r10505 r10714  
    4242     */
    4343    public boolean create(String nom) throws JiwigoException;
     44
     45    /**
     46     * Deletes a category
     47     * @param id id of the category
     48     * @return
     49     * @throws JiwigoException
     50     */
     51    public boolean delete(Category category) throws JiwigoException;
    4452}
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/CategoryServiceImpl.java

    r10505 r10714  
    107107    }
    108108
     109    public boolean delete(Category category) throws JiwigoException {
     110        if (category.getIdentifier() == null) {
     111            throw new JiwigoException("The identifier of the category cannot be null");
     112        } else {
     113            return dao.delete(category);
     114        }
     115    }
     116
    109117}
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/enumeration/MethodsEnum.java

    r9879 r10714  
    2626            "pwg.images.getInfo"), AJOUTER_CATEGORIE("pwg.categories.add"), AJOUTER_COMMENTAIRE("pwg.images.addComment"), LISTER_TAGS(
    2727            "pwg.tags.getList"), TAGS_ADMIN_LIST("pwg.tags.getAdminList"), ADD_TAG("pwg.tags.add"), SET_INFO(
    28             "pwg.images.setInfo"), SEARCH("pwg.images.search"), SET_PRIVACY_LEVEL("pwg.images.setPrivacyLevel");
     28            "pwg.images.setInfo"), SEARCH("pwg.images.search"), SET_PRIVACY_LEVEL("pwg.images.setPrivacyLevel"), ADD_SIMPLE(
     29            "pwg.images.addSimple"), ADD_IMAGE("pwg.images.add"), ADD_CHUNK("pwg.images.addChunk"), DELETE_CATEGORY(
     30            "pwg.categories.delete"), SESSION_STATUS("pwg.session.getStatus");
    2931
    3032    protected String label;
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/impl/SessionManagerImpl.java

    r10698 r10714  
    161161        }
    162162        doc = executeReturnDocument(MethodsEnum.LOGIN.getLabel(), "username", login, "password", password);
     163        if (LOG.isDebugEnabled()) {
     164            LOG.debug("XML connection : " + Tools.documentToString(doc));
     165        }
    163166        try {
    164167            return (Tools.checkOk(doc) ? 0 : 1);
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java

    r10090 r10714  
    229229            return true;
    230230        } else {
    231             LOG.error("Resultat : " + doc.getDocumentElement().getAttribute("stat") + "\nDocument retourné : \n"
     231            LOG.error("Resultat : " + doc.getDocumentElement().getAttribute("stat") + "\nDocument retourne : \n"
    232232                    + Tools.documentToString(doc));
    233233            if (((Element) doc.getDocumentElement().getElementsByTagName("err").item(0)).getAttribute("msg").equals(
     
    352352        Element el = (Element) element.getElementsByTagName(tagName).item(0);
    353353        if (el != null) {
    354                 return el.getFirstChild().getNodeValue();
     354            return el.getFirstChild().getNodeValue();
    355355        }
    356356        // if not, empty string is safer then null
Note: See TracChangeset for help on using the changeset viewer.