Skip to content

Commit

Permalink
#117 implemented mapper for migration legacy data from sql to nosql. …
Browse files Browse the repository at this point in the history
…Migration isn't implemented right now.
  • Loading branch information
rinkesj committed Jun 21, 2015
1 parent dc928b9 commit 7fad9d4
Show file tree
Hide file tree
Showing 9 changed files with 594 additions and 46 deletions.
61 changes: 31 additions & 30 deletions src/main/java/cz/zcu/kiv/eegdatabase/logic/xml/XMLTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,43 @@
*/
package cz.zcu.kiv.eegdatabase.logic.xml;

import cz.zcu.kiv.eegdatabase.data.pojo.*;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.*;
import cz.zcu.kiv.eegdatabase.logic.controller.experiment.MetadataCommand;
import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ibm.icu.util.Calendar;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cz.zcu.kiv.eegdatabase.data.pojo.DataFile;
import cz.zcu.kiv.eegdatabase.data.pojo.Experiment;
import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentOptParamVal;
import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamVal;
import cz.zcu.kiv.eegdatabase.data.pojo.Hardware;
import cz.zcu.kiv.eegdatabase.data.pojo.Person;
import cz.zcu.kiv.eegdatabase.data.pojo.PersonOptParamVal;
import cz.zcu.kiv.eegdatabase.data.pojo.Scenario;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.DataType;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.FileMetadataType;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.HardwareType;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.MeasurationAddParam;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.MeasurationType;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.ObjectFactory;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.PersonAddParam;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.PersonType;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.ScenarioType;
import cz.zcu.kiv.eegdatabase.data.xmlObjects.WeatherType;
import cz.zcu.kiv.eegdatabase.logic.controller.experiment.MetadataCommand;
import cz.zcu.kiv.eegdatabase.wui.components.utils.DateUtils;
import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils;

/**
*
* @author Jan Štěbeták
Expand Down Expand Up @@ -174,20 +188,7 @@ protected void writePerson(List<PersonType> perType, Person per,
if (mc.isBirth()) {
if (per.getDateOfBirth() != null && scenarioStartTime != null) {

Calendar toTime = Calendar.getInstance();
toTime.setTimeInMillis(scenarioStartTime.getTime());

Calendar birthDate = Calendar.getInstance();
birthDate.setTimeInMillis(per.getDateOfBirth().getTime());

int years = toTime.get(Calendar.YEAR) - birthDate.get(Calendar.YEAR);
int currMonth = toTime.get(Calendar.MONTH) + 1;
int birthMonth = birthDate.get(Calendar.MONTH) + 1;
int months = currMonth - birthMonth;

if (months < 0)
years--;

int years = DateUtils.getPersonAge(per, scenarioStartTime);
pert.setAge(Integer.toString(years));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cz.zcu.kiv.eegdatabase.wui.components.utils;

import java.sql.Timestamp;

import com.ibm.icu.util.Calendar;

import cz.zcu.kiv.eegdatabase.data.pojo.Person;

public class DateUtils {

public static int getPersonAge(Person per, Timestamp scenarioStartTime) {
Calendar toTime = Calendar.getInstance();
toTime.setTimeInMillis(scenarioStartTime.getTime());

Calendar birthDate = Calendar.getInstance();
birthDate.setTimeInMillis(per.getDateOfBirth().getTime());

int years = toTime.get(Calendar.YEAR) - birthDate.get(Calendar.YEAR);
int currMonth = toTime.get(Calendar.MONTH) + 1;
int birthMonth = birthDate.get(Calendar.MONTH) + 1;
int months = currMonth - birthMonth;

if (months < 0)
years--;
return years;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
******************************************************************************/
package cz.zcu.kiv.eegdatabase.wui.components.utils;

import java.sql.Timestamp;

import com.ibm.icu.util.Calendar;

import cz.zcu.kiv.eegdatabase.data.pojo.Person;

/**
* Utilities class for string.
*
Expand Down Expand Up @@ -52,4 +58,5 @@ public static String randomString(int min, int max)
public static String getCaptchaString(){
return randomString(3, 8);
}

}
Loading

0 comments on commit 7fad9d4

Please sign in to comment.