@Test public void testLoadTwoRootObjectsWithNoType() throws JsonProcessingException { JsonNode data = mapper .createArrayNode() .add( mapper.createObjectNode().put("userId", "1").put("name", "Paul").put("sex", "MALE")) .add( mapper .createObjectNode() .put("userId", "2") .put("name", "Anna") .put("sex", "FEMALE")); Resource result = mapper .reader() .withAttribute(RESOURCE_SET, resourceSet) .withAttribute(ROOT_ELEMENT, ModelPackage.Literals.USER) .treeToValue(data, Resource.class); assertNotNull(result); assertEquals(2, result.getContents().size()); User first = (User) result.getContents().get(0); User second = (User) result.getContents().get(1); assertEquals("1", first.getUserId()); assertEquals("Paul", first.getName()); assertEquals("MALE", first.getSex().getLiteral()); assertEquals("2", second.getUserId()); assertEquals("Anna", second.getName()); assertEquals("FEMALE", second.getSex().getLiteral()); }
public void storeUserData(User user) { SharedPreferences.Editor userLocalDatabaseEditor = userLocalDatabase.edit(); userLocalDatabaseEditor.putString("name", user.getName()); userLocalDatabaseEditor.putString("username", user.getUsername()); userLocalDatabaseEditor.putString("password", user.getPassword()); userLocalDatabaseEditor.putString("sex", user.getSex()); userLocalDatabaseEditor.putInt("age", user.getAge()); userLocalDatabaseEditor.putInt("height", user.getHeight()); userLocalDatabaseEditor.putInt("weight", user.getWeight()); userLocalDatabaseEditor.putInt("physAct", user.getPhysAct()); userLocalDatabaseEditor.commit(); }
/** Build a Criteria object from the data object for this peer */ public static Criteria buildCriteria(User obj) { Criteria criteria = new Criteria(DATABASE_NAME); if (!obj.isNew()) criteria.add(ID, obj.getId()); criteria.add(NAME, obj.getName()); criteria.add(PASSWORD, obj.getPassword()); criteria.add(TRUE_NAME, obj.getTrueName()); criteria.add(TEAM, obj.getTeam()); criteria.add(SEX, obj.getSex()); criteria.add(BIRTH, obj.getBirth()); criteria.add(LASTLOGINDATE, obj.getLastlogindate()); return criteria; }
@Test public void testLoadSingleObjectWithNoType() throws JsonProcessingException { JsonNode data = mapper.createObjectNode().put("userId", "1").put("name", "Paul"); User result = mapper .reader() .withAttribute(ROOT_ELEMENT, ModelPackage.Literals.USER) .treeToValue(data, User.class); assertNotNull(result); assertEquals("1", result.getUserId()); assertEquals("Paul", result.getName()); assertEquals("MALE", result.getSex().getLiteral()); }
@Test public void testLoadSingleObjectWithNoTypeAndOneContainment() throws JsonProcessingException { JsonNode data = mapper .createObjectNode() .put("userId", "1") .put("name", "Paul") .set("address", mapper.createObjectNode().put("addId", "a1").put("city", "Prague")); User result = mapper .reader() .withAttribute(RESOURCE_SET, resourceSet) .withAttribute(ROOT_ELEMENT, ModelPackage.Literals.USER) .treeToValue(data, User.class); assertNotNull(result); assertEquals("1", result.getUserId()); assertEquals("Paul", result.getName()); assertEquals("MALE", result.getSex().getLiteral()); assertNotNull(result.getAddress()); }
/* * (non-Javadoc) * * @see * org.openiam.idm.srvc.user.service.UserDataService#getUserAsMap(java.lang * .String) */ @Transactional(readOnly = true) public Map<String, UserAttribute> getUserAsMap(String userId) { User usr = getUser(userId); if (usr == null) { return null; } Map<String, UserAttribute> attrMap = getAllAttributes(userId); if (attrMap == null) { attrMap = new HashMap<String, UserAttribute>(); } // assign the predefined properties attrMap.put("USER_ID", new UserAttribute(null, userId, null, "USER_ID", userId)); attrMap.put( "FIRST_NAME", new UserAttribute(null, userId, null, "FIRST_NAME", usr.getFirstName())); attrMap.put("LAST_NAME", new UserAttribute(null, userId, null, "LAST_NAME", usr.getLastName())); attrMap.put( "MIDDLE_INIT", new UserAttribute(null, userId, null, "MIDDLE_INIT", String.valueOf(usr.getMiddleInit()))); attrMap.put("TITLE", new UserAttribute(null, userId, null, "TITLE", usr.getTitle())); attrMap.put("DEPT", new UserAttribute(null, userId, null, "DEPT", usr.getDeptCd())); attrMap.put( "STATUS", new UserAttribute(null, userId, null, "STATUS", usr.getStatus().toString())); if (usr.getBirthdate() != null) { attrMap.put( "BIRTHDATE", new UserAttribute(null, userId, null, "BIRTHDATE", usr.getBirthdate().toString())); } else { attrMap.put("BIRTHDATE", new UserAttribute(null, userId, null, "BIRTHDATE", null)); } attrMap.put("SEX", new UserAttribute(null, userId, null, "SEX", String.valueOf(usr.getSex()))); if (usr.getCreateDate() != null) { attrMap.put( "CREATE_DATE", new UserAttribute(null, userId, null, "CREATE_DATE", usr.getCreateDate().toString())); } else { attrMap.put("CREATE_DATE", new UserAttribute(null, userId, null, "CREATE_DATE", null)); } attrMap.put( "CREATED_BY", new UserAttribute(null, userId, null, "CREATED_BY", usr.getCreatedBy())); if (usr.getLastUpdate() != null) { attrMap.put( "LAST_UPDATE", new UserAttribute(null, userId, null, "LAST_UPDATE", usr.getLastUpdate().toString())); } else { attrMap.put("LAST_UPDATE", new UserAttribute(null, userId, null, "LAST_UPDATE", null)); } attrMap.put( "LAST_UPDATEDBY", new UserAttribute(null, userId, null, "LAST_UPDATEDBY", usr.getLastUpdatedBy())); attrMap.put("PREFIX", new UserAttribute(null, userId, null, "PREFIX", usr.getPrefix())); attrMap.put("SUFFIX", new UserAttribute(null, userId, null, "SUFFIX", usr.getSuffix())); attrMap.put( "USER_TYPE_IND", new UserAttribute(null, userId, null, "USER_TYPE_IND", usr.getUserTypeInd())); attrMap.put( "EMPLOYEE_ID", new UserAttribute(null, userId, null, "EMPLOYEE_ID", usr.getEmployeeId())); attrMap.put( "EMPLOYEE_TYPE", new UserAttribute(null, userId, null, "EMPLOYEE_TYPE", usr.getEmployeeType())); attrMap.put( "LOCATION_ID", new UserAttribute(null, userId, null, "LOCATION_ID", usr.getLocationCd())); attrMap.put( "ORGANIZATION_ID", new UserAttribute(null, userId, null, "ORGANIZATION_ID", usr.getCompanyId())); attrMap.put( "COMPANY_OWNER_ID", new UserAttribute(null, userId, null, "COMPANY_OWNER_ID", usr.getCompanyOwnerId())); attrMap.put( "MANAGER_ID", new UserAttribute(null, userId, null, "MANAGER_ID", usr.getManagerId())); attrMap.put("JOB_CODE", new UserAttribute(null, userId, null, "JOB_CODE", usr.getJobCode())); return attrMap; }