Search in sources :

Example 96 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class UploadInterruptedTest method testUnreliableUpload_Test3_FailsAtDatabaseFile.

@Test
public void testUnreliableUpload_Test3_FailsAtDatabaseFile() throws Exception {
    /*
		 * This test fails when trying to upload the first database file, but succeeds on retry
		 *
		 * 1. upload(action-up-987, actions/action-up-987)
		 * 2. upload(transaction-123, transactions/transaction-123)
		 * 3. upload(multichunk-1, temp-1)
		 * 5. upload(database-123, temp-2) <<< FAILS HERE
		 * 6. move(temp-1, multichunks/multichunk-1)
		 * 8. move(temp-2, databases/database-123)
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { "rel=[456].+upload.+database" }));
    TestClient clientA = new TestClient("A", testConnection);
    // 1. First upload fails
    clientA.createNewFile("A-original", 10);
    boolean upFailed = false;
    try {
        clientA.up();
    } catch (StorageException e) {
        upFailed = true;
        logger.log(Level.INFO, e.getMessage());
    }
    assertTrue(upFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/temporary/").listFiles().length);
    File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
    TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);
    assertEquals(2, transactionTO.getActions().size());
    assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("database-"));
    // 2. Second try succeeds and must clean up the transactions
    clientA.up();
    assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/temporary/").listFiles().length);
    // Tear down
    clientA.deleteTestData();
}
Also used : UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) TransactionTO(org.syncany.plugins.transfer.to.TransactionTO) Test(org.junit.Test)

Example 97 with Persister

use of org.simpleframework.xml.core.Persister in project project1-ICS372 by sandip-rai.

the class XmlHandler method readXMLFile.

/**
 * Read XML file.
 *
 * @param path
 *            the file
 * @return true, if successful
 * @throws Exception
 */
public boolean readXMLFile(String path) throws Exception {
    // Decide how to handle unknown patients and readings based on system settings
    boolean addPatients = clinicalTrial.getSettings().xmlAddUnknownPatients();
    boolean addReadings = clinicalTrial.getSettings().xmlAddUnknownReadings();
    File file = new File(path);
    Serializer serializer = new Persister();
    ReadingSet readingSet = serializer.read(ReadingSet.class, file);
    // Convert from a reading set to an ArrayList of FileReadings so that the data
    // can be processed
    ArrayList<FileReading> fileReadings = getFileReading(readingSet);
    // Attempt to add the clinics to the trial
    addClinicToTrial(fileReadings);
    // the trial
    if (addPatients) {
        addPatientsToTrial(fileReadings, addReadings);
    }
    // Add readings from input file to Patient's readings ArrayList
    AddReadingToPatient(fileReadings);
    return true;
}
Also used : Persister(org.simpleframework.xml.core.Persister) File(java.io.File) Serializer(org.simpleframework.xml.Serializer)

Example 98 with Persister

use of org.simpleframework.xml.core.Persister in project project1-ICS372 by sandip-rai.

the class XmlHandler method readXMLFile.

/**
 * Read XML file.
 *
 * @param file
 *            the file
 * @return true, if successful
 * @throws Exception
 */
public boolean readXMLFile(String path) throws Exception {
    // Decide how to handle unknown patients and readings based on system settings
    boolean addPatients = clinicalTrial.getSettings().xmlAddUnknownPatients();
    boolean addReadings = clinicalTrial.getSettings().xmlAddUnknownReadings();
    try {
        File file = new File(path);
        Serializer serializer = new Persister();
        ReadingSet readingSet = serializer.read(ReadingSet.class, file);
        // Convert from a reading set to an ArrayList of FileReadings so that the data
        // can be processed
        ArrayList<FileReading> fileReadings = getFileReading(readingSet);
        // Attempt to add the clinics to the trial
        addClinicToTrial(fileReadings);
        // the trial
        if (addPatients) {
            addPatientsToTrial(fileReadings, addReadings);
        }
        // Add readings from input file to Patient's readings ArrayList
        AddReadingToPatient(fileReadings);
        return true;
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : Persister(org.simpleframework.xml.core.Persister) File(java.io.File) Serializer(org.simpleframework.xml.Serializer)

Example 99 with Persister

use of org.simpleframework.xml.core.Persister in project applause by applause.

the class JobByIdProvider method extractItem.

protected JobOffer extractItem(Reader reader) throws Exception {
    Serializer serializer = new Persister();
    Jobs root = serializer.read(Jobs.class, reader);
    return root.getJobOffer();
}
Also used : Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 100 with Persister

use of org.simpleframework.xml.core.Persister in project applause by applause.

the class CareerDataProvider method extractItem.

protected Career extractItem(Reader reader) throws Exception {
    Serializer serializer = new Persister();
    Data root = serializer.read(Data.class, reader);
    return root.getCareer();
}
Also used : Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Aggregations

Persister (org.simpleframework.xml.core.Persister)175 Serializer (org.simpleframework.xml.Serializer)139 StringWriter (java.io.StringWriter)74 Writer (java.io.Writer)62 Registry (org.simpleframework.xml.convert.Registry)23 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)23 Strategy (org.simpleframework.xml.strategy.Strategy)23 File (java.io.File)18 AnnotationStrategy (org.simpleframework.xml.convert.AnnotationStrategy)18 Test (org.junit.Test)14 IOException (java.io.IOException)12 StorageException (org.syncany.plugins.transfer.StorageException)8 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)6 ConfigTO (org.syncany.config.to.ConfigTO)5 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)4