Package org.spw.model

Examples of org.spw.model.Document


        }
    }
   
    public Document read(Long key) {
        EntityManager em = emf.createEntityManager();
        Document retValue = null;
        try {
            retValue = em.find(Document.class, key);
        } catch (Exception e) {
            Logger.getLogger(DocumentController.class.getName()).log(Level.SEVERE, "Error reading " + key, e);
            if (em.getTransaction().isActive())
View Full Code Here


        }
        return retValue;
    }
   
    public Document update(Document object) {
        Document result = null;
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            result = em.merge(object);
            em.getTransaction().commit();
View Full Code Here

   
    public void delete(Document object) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            Document entity = em.find(Document.class, object.getIdDocument());
            em.remove(entity);
            em.getTransaction().commit();
        } catch (Exception e) {
            Logger.getLogger(DocumentController.class.getName()).log(Level.SEVERE, "Error deleting " + object, e);
            if (em.getTransaction().isActive())
View Full Code Here

    public Document parse(String documentString) {
        int begin = documentString.lastIndexOf('[') + 1;
        int last  = documentString.lastIndexOf(']');
        if (begin < 0 || last < 0 || begin > last) return null;

        Document retValue = null;
        String number = documentString.substring(begin, last);
        try {
            retValue = read(Long.parseLong(number));
        } catch (NumberFormatException ex) {
            //incorrect number, could not happen
View Full Code Here

        boolean found1 = false;
        boolean found2 = false;
       
        ContactController instance = new ContactController();
        Contact contact = instance.read(TEST_ID_ABC1);
        Document doc1 = new Document();
        doc1.setContact(contact);
        doc1.setDocumentType("Test1");
        doc1.setTitle(getName());
       
        Document doc2 = new Document();
        doc2.setContact(contact);
        doc2.setDocumentType("Test2");
        doc2.setTitle(getName());
       
        doc1 = instance.addDocument(doc1);
        doc2 = instance.addDocument(doc2);
        assertEquals(contact, doc1.getContact());
        assertEquals(contact, doc2.getContact());
        for(Document aDoc : doc2.getContact().getDocumentLinks()) {
            if (aDoc.getTitle().equals(getName())
            && aDoc.getDocumentType().equals("Test1")) {
                found1 = true;
            }
            if (aDoc.getTitle().equals(getName())
            && aDoc.getDocumentType().equals("Test2")) {
                found2 = true;
            }
        }
        assertTrue("The added 1rst test document is not found", found1);
        assertTrue("The added 2nd test document is not found", found2);
       
        //check if donations can be read
        DocumentController documentCtrl = new DocumentController();
        assertNotNull(documentCtrl.read(doc1.getIdDocument()));
        assertNotNull(documentCtrl.read(doc2.getIdDocument()));
       
        //check update an existing donation
        doc1.setDocumentType("Test3");
        instance.addDocument(doc1);
        assertEquals("Test3", documentCtrl.read(doc1.getIdDocument()).getDocumentType());
View Full Code Here

        boolean found2 = false;
       
        ContactController instance = new ContactController();
        DocumentController docCtrl = new DocumentController();
        Contact contact = instance.read(TEST_ID_ABC1);
        Document doc1 = new Document();
        doc1.setContact(contact);
        doc1.setDocumentType("Test1");
        doc1.setTitle(getName());
       
        Document doc2 = new Document();
        doc2.setContact(contact);
        doc2.setDocumentType("Test2");
        doc2.setTitle(getName());
       
        doc1 = instance.addDocument(doc1);
        doc2 = instance.addDocument(doc2);
        assertEquals(contact, doc1.getContact());
        assertEquals(contact, doc2.getContact());

        contact = instance.removeDocument(doc1);
        contact = instance.removeDocument(doc2);
        for(Document aDoc : contact.getDocumentLinks()) {
            if (aDoc.getTitle().equals(getName())
            && aDoc.getDocumentType().equals("Test1")) {
                found1 = true;
                break;
            }
            if (aDoc.getTitle().equals(getName())
            && aDoc.getDocumentType().equals("Test2")) {
                found2 = true;
                break;
            }
        }
        assertFalse("The removed 1rst test is found", found1);
        assertFalse("The removed 2nd test is found", found2);
       
        //check if donations can be read
        assertNull(docCtrl.read(doc1.getIdDocument()));
        assertNull(docCtrl.read(doc2.getIdDocument()));
    }
View Full Code Here

        return "success";
    }
   
    public String buttonRemove_action() {
        RowKey rk = tableRowGroup1.getRowKey();
        Document document;
        if (rk != null) {
            document = (Document)list.getObject(rk);
        } else {
            return null;
        }

        String filename = document.getDocumentLink();
        File file = new File(DocumentFileManager.
                getFilenameOnServer(filename, getServerPath()));
        file.delete();
        removeDocument(document);
       
View Full Code Here

        //* Bug if you display a document with a link
        // --> use a button (see http://blogs.sun.com/tor/entry/creating_downloadable_files)
       
        //TODO: refactor this to move all the file specific actions to a new class
        RowKey rk = tableRowGroup1.getRowKey();
        Document document;
        if (rk != null) {
            document = (Document)list.getObject(rk);
        } else {
            error("This document has been removed.");
            return null;
        }
       
        String filename = document.getDocumentLink();
        String contentType = document.getDocumentType();
        if (contentType == null)
            contentType = "application/x-download";
        File file = new File(DocumentFileManager.
                getFilenameOnServer(filename, getServerPath()));
        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
View Full Code Here

        return null;
    }

    public String buttonDetach_action() {
        RowKey rk = tableRowGroup1.getRowKey();
        Document document;
        if (rk != null) {
            document = (Document)list.getObject(rk);
        } else {
            return null;
        }
View Full Code Here

    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value == null) return null;
        if (!(value instanceof Document)) {
            throw new ConverterException("Error converting Document, got a " + value.getClass().getName());
        }
        Document obj = (Document) value;
        return Long.toString(obj.getIdDocument());
    }
View Full Code Here

TOP

Related Classes of org.spw.model.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.