DMZSyncServiceImpl extends RemoteServiceServlet implements
		DMZSyncService { @Override public void pullFromDMZ(Long standardizedPatientId) throws DMZSyncException { String url = getHostAddress() + "/DataImportExport/exportSP?id=" + standardizedPatientId; String data = getDMZData(url); data =preProcessData(data); JSONDeserializer deserializer = new JSONDeserializer() .use("anamnesisForm.createDate", new DateTransformer("yyyy-MM-dd'T'HH:mm:ss'Z'")) .use("birthday", new DateTransformer("yyyy-MM-dd")) .use("gender", new GenderTransformer()) .use("maritalStatus", new MaritalStatusTransformer()) .use("status",new SPStatusTransformer()) .use("workPermission", new WorkPermissionTransformer()) .use("anamnesisForm.anamnesischecksvalues.values.anamnesischeck.title.type", new AnamnesisChecksTypeTransformet()) .use("anamnesisForm.scars.values.traitType", new TraitTypeTransformet()) .use("anamnesisForm.anamnesischecksvalues.values.anamnesischeck.type", new AnamnesisChecksTypeTransformet()); String unExpectedData=standardizedPatientId+"not found"; StandardizedPatient newPatient = null; if(!data.equals(unExpectedData)){ try{ newPatient = (StandardizedPatient) (deserializer .use(null, StandardizedPatient.class).deserialize(data)); }catch(flexjson.JSONException e){ Log.error("Error deserialize json data: "+e.getMessage()); throw new DMZSyncException(DMZSyncExceptionType.SYNC_PATIENT_EXCEPTION,"Error json data."); } }else{ throw new DMZSyncException(DMZSyncExceptionType.PATIENT_EXIST_EXCEPTION,""); } StandardizedPatient patient = StandardizedPatient.findStandardizedPatient(standardizedPatientId); if( patient != null){ if(newPatient!=null){ updatePatient(patient,newPatient); } }else{ } }  @Override List<String> pushToDMZ(Long standardizedPatientId,String locale); @Override void pullFromDMZ(Long standardizedPatientId); @Override String sendSync(String locale); @Override void getSync(String locale); String preProcessData(String data);  }
@Test public void testPullFromDMZ() { testData = new StandardizedPatient(); testData.setName("patient1"); testData.persist(); testData.merge(); dataFromDMZ = "{\"class\":\"sp_portal.local.StandardizedPatient\",\"id\":"+testData.getId()+",\"anamnesisForm\":{\"class\":\"sp_portal.local.AnamnesisForm\",\"id\":5,\"anamnesisChecksValues\":[{\"class\":\"sp_portal.local.AnamnesisChecksValue\",\"id\":10,\"anamnesisCheck\":{\"class\":\"sp_portal.local.AnamnesisCheck\",\"id\":8,\"origId\":5,\"sortOrder\":6,\"text\":\"Leiden Sie unter Diabetes?\",\"title\":{\"class\":\"sp_portal.local.AnamnesisCheck\",\"id\":2,\"origId\":11,\"sortOrder\":5,\"text\":\"Disease history category\",\"title\":null,\"type\":4,\"userSpecifiedOrder\":null,\"value\":\"\"},\"type\":1,\"userSpecifiedOrder\":null,\"value\":\"\"},\"anamnesisChecksValue\":null,\"anamnesisForm\":{\"_ref\":\"../..\",\"class\":\"sp_portal.local.AnamnesisForm\"},\"comment\":null,\"origId\":15,\"truth\":false},{\"class\":\"sp_portal.local.AnamnesisChecksValue\",\"id\":9,\"anamnesisCheck\":{\"class\":\"sp_portal.local.AnamnesisCheck\",\"id\":4,\"origId\":1,\"sortOrder\":2,\"text\":\"Rauchen Sie?\",\"title\":{\"class\":\"sp_portal.local.AnamnesisCheck\",\"id\":1,\"origId\":10,\"sortOrder\":1,\"text\":\"Personal lifestyle category\",\"title\":null,\"type\":4,\"userSpecifiedOrder\":null,\"value\":\"\"},\"type\":1,\"userSpecifiedOrder\":null,\"value\":\"\"},\"anamnesisChecksValue\":null,\"anamnesisForm\":{\"_ref\":\"../..\",\"class\":\"sp_portal.local.AnamnesisForm\"},\"comment\":null,\"origId\":14,\"truth\":false}],\"createDate\":\"2009-09-18T16:00:00Z\",\"origId\":6,\"scars\":[],\"standardizedPatients\":[{\"_ref\":\"../..\",\"class\":\"sp_portal.local.StandardizedPatient\"}]},\"bankaccount\":{\"class\":\"sp_portal.local.Bankaccount\",\"id\":5,\"bankName\":\"KTS\",\"bic\":\"BENDSFF1JEV\",\"city\":null,\"iban\":\"CH78 5685 7565 4364 7\",\"origId\":31,\"ownerName\":null,\"postalCode\":null,\"standardizedPatients\":[{\"_ref\":\"../..\",\"class\":\"sp_portal.local.StandardizedPatient\"}]},\"birthday\":\"1965-09-23T16:00:00Z\",\"city\":\"Basel\",\"description\":null,\"email\":\"beddebu@hss.ch\",\"gender\":1,\"height\":182,\"immagePath\":null,\"maritalStatus\":null,\"mobile\":\"078 586 29 84\",\"name\":\"Buser\",\"nationality\":{\"class\":\"sp_portal.local.Nationality\",\"id\":2,\"nationality\":\"Deutschland\",\"origId\":6},\"origId\":23,\"postalCode\":4051,\"preName\":\"Bettina\",\"profession\":{\"class\":\"sp_portal.local.Profession\",\"id\":5,\"origId\":6,\"profession\":\"Florist/in\"},\"socialInsuranceNo\":null,\"street\":\"Rankenbergweg 1\",\"telephone\":null,\"telephone2\":null,\"videoPath\":null,\"weight\":82,\"workPermission\":null}"; try { instance.pullFromDMZ(testData.getId()); } catch (Exception e1) { e1.printStackTrace(); e1.getCause().printStackTrace(); Assert.fail("error occured " + e1.getMessage()); } StandardizedPatient patient = StandardizedPatient.findStandardizedPatient(testData.getId()); assertEquals(testData.getId(), (Long)instance.spParam); assertEquals("Buser",patient.getName()); assertEquals("Bettina",patient.getPreName()); assertEquals("Rankenbergweg 1",patient.getStreet()); assertEquals("Basel",patient.getCity()); assertEquals((Integer)4051,patient.getPostalCode()); assertEquals(null,patient.getTelephone()); assertEquals(null,patient.getTelephone2()); assertEquals("078 586 29 84",patient.getMobile()); assertEquals((Integer)182,patient.getHeight()); assertEquals((Integer)82,patient.getWeight()); assertEquals(null,patient.getImmagePath()); assertEquals(null,patient.getVideoPath()); Date expectedDate = null ; try { String str_date="2009-09-18T16:00:00Z"; DateFormat formatter ; formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); expectedDate = (Date)formatter.parse(str_date); } catch (ParseException e){ fail("format error"); } }
@Test public void testPullFemaleFromDMZ() { testData = new StandardizedPatient(); testData.setName("patient2"); testData.persist(); testData.merge(); dataFromDMZ = "{\"class\":\"sp_portal.local.StandardizedPatient\",\"id\":"+testData.getId()+",\"anamnesisForm\":{\"class\":\"sp_portal.local.AnamnesisForm\",\"id\":5,\"anamnesisChecksValues\":[{\"class\":\"sp_portal.local.AnamnesisChecksValue\",\"id\":10,\"anamnesisCheck\":{\"class\":\"sp_portal.local.AnamnesisCheck\",\"id\":8,\"origId\":5,\"sortOrder\":6,\"text\":\"Leiden Sie unter Diabetes?\",\"title\":{\"class\":\"sp_portal.local.AnamnesisCheck\",\"id\":2,\"origId\":11,\"sortOrder\":5,\"text\":\"Disease history category\",\"title\":null,\"type\":4,\"userSpecifiedOrder\":null,\"value\":\"\"},\"type\":1,\"userSpecifiedOrder\":null,\"value\":\"\"},\"anamnesisChecksValue\":null,\"anamnesisForm\":{\"_ref\":\"../..\",\"class\":\"sp_portal.local.AnamnesisForm\"},\"comment\":null,\"origId\":15,\"truth\":false},{\"class\":\"sp_portal.local.AnamnesisChecksValue\",\"id\":9,\"anamnesisCheck\":{\"class\":\"sp_portal.local.AnamnesisCheck\",\"id\":4,\"origId\":1,\"sortOrder\":2,\"text\":\"Rauchen Sie?\",\"title\":{\"class\":\"sp_portal.local.AnamnesisCheck\",\"id\":1,\"origId\":10,\"sortOrder\":1,\"text\":\"Personal lifestyle category\",\"title\":null,\"type\":4,\"userSpecifiedOrder\":null,\"value\":\"\"},\"type\":1,\"userSpecifiedOrder\":null,\"value\":\"\"},\"anamnesisChecksValue\":null,\"anamnesisForm\":{\"_ref\":\"../..\",\"class\":\"sp_portal.local.AnamnesisForm\"},\"comment\":null,\"origId\":14,\"truth\":false}],\"createDate\":\"2009-09-18T16:00:00Z\",\"origId\":6,\"scars\":[],\"standardizedPatients\":[{\"_ref\":\"../..\",\"class\":\"sp_portal.local.StandardizedPatient\"}]},\"bankaccount\":{\"class\":\"sp_portal.local.Bankaccount\",\"id\":5,\"bankName\":\"KTS\",\"bic\":\"BENDSFF1JEV\",\"city\":null,\"iban\":\"CH78 5685 7565 4364 7\",\"origId\":31,\"ownerName\":null,\"postalCode\":null,\"standardizedPatients\":[{\"_ref\":\"../..\",\"class\":\"sp_portal.local.StandardizedPatient\"}]},\"birthday\":\"1965-09-23T16:00:00Z\",\"city\":\"Basel\",\"description\":null,\"email\":\"beddebu@hss.ch\",\"gender\":2,\"height\":182,\"immagePath\":null,\"maritalStatus\":null,\"mobile\":\"078 586 29 84\",\"name\":\"Buser\",\"nationality\":{\"class\":\"sp_portal.local.Nationality\",\"id\":2,\"nationality\":\"Deutschland\",\"origId\":6},\"origId\":23,\"postalCode\":4051,\"preName\":\"Bettina\",\"profession\":{\"class\":\"sp_portal.local.Profession\",\"id\":5,\"origId\":6,\"profession\":\"Florist/in\"},\"socialInsuranceNo\":null,\"street\":\"Rankenbergweg 1\",\"telephone\":null,\"telephone2\":null,\"videoPath\":null,\"weight\":82,\"workPermission\":null}"; try { instance.pullFromDMZ(testData.getId()); } catch (Exception e) { e.printStackTrace(); e.getCause().printStackTrace(); Assert.fail("error occured " + e.getMessage()); } StandardizedPatient patient = StandardizedPatient.findStandardizedPatient(testData.getId()); assertEquals(testData.getId(), (Long)instance.spParam); assertEquals(Gender.FEMALE,patient.getGender()); assertEquals("Buser",patient.getName()); assertEquals("Bettina",patient.getPreName()); assertEquals("Rankenbergweg 1",patient.getStreet()); assertEquals("Basel",patient.getCity()); assertEquals((Integer)4051,patient.getPostalCode()); assertEquals(null,patient.getTelephone()); assertEquals(null,patient.getTelephone2()); assertEquals("078 586 29 84",patient.getMobile()); assertEquals((Integer)182,patient.getHeight()); assertEquals((Integer)82,patient.getWeight()); assertEquals(null,patient.getImmagePath()); assertEquals(null,patient.getVideoPath()); }
@Test public void testPullErrorJsonFromDMZ() { testData = new StandardizedPatient(); testData.setName("patient"); testData.persist(); testData.merge(); dataFromDMZ = "abc"; try { instance.pullFromDMZ(testData.getId()); Assert.fail("Pull StandardizedPatient from DMZ by error json data without throws Exception!"); } catch (Exception e) { } }