Java tutorial
/* * Copyright (c) 2013, Helome and/or its affiliates. All rights reserved. * Helome PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * Created on 201492 */ package mobile.vo.rns; import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import mobile.vo.MobileVO; import models.Expert; import models.Require; import models.SkillTag; import org.apache.commons.lang.StringUtils; import org.joda.time.DateTime; import play.libs.Json; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import common.jackjson.JackJsonUtil; /** * * * @ClassName: RequireVO * @Description: VO * @date 201492 ?7:00:26 * @author ShenTeng * */ public class RequireVO implements MobileVO { /** id */ private Long id; /** id */ private Long ownerUserId; /** ?? */ private String ownerUsername; /** 7070? */ private String ownerAvatar_70; /** */ private String ownerJob; /** */ private String ownerCountry; /** id */ private Long industryId; /** ?? */ private String industryName; /** */ private String title; /** */ private String info; /** */ private String budget; /** ? */ private String createDate; /** ["ddd",""] */ private List<String> tags = new ArrayList<String>(); public static RequireVO create(Require po) { ObjectMapper objectMapper = JackJsonUtil.getMapperInstance(false); RequireVO vo = new RequireVO(); vo.setId(po.getId()); vo.setOwnerUserId(po.getOwner().getId()); vo.setOwnerUsername(po.getOwner().getUserNameOrEmail()); vo.setOwnerAvatar_70(po.getOwner().getAvatar(70)); Expert ownerExpert = po.getOwner().getExperts().iterator().next(); vo.setOwnerJob(ownerExpert.job); vo.setOwnerCountry(ownerExpert.country); SkillTag industry = po.getIndustry(); if (null != industry) { vo.setIndustryId(industry.getId()); vo.setIndustryName(industry.getTagName()); } vo.setTitle(po.getTitle()); vo.setInfo(po.getInfo()); if (null == po.getBudget()) { vo.setBudget("-1"); // -1 - ? } else { vo.setBudget(new BigDecimal(po.getBudget()).setScale(1, BigDecimal.ROUND_HALF_UP).toString()); } vo.setCreateDate(new DateTime(po.getCreateDate()).toString("yyyy-MM-dd HH:mm:ss")); if (StringUtils.isNotBlank(po.getTags())) { try { @SuppressWarnings("unchecked") List<String> readValue = objectMapper.readValue(po.getTags(), List.class); vo.setTags(readValue); } catch (IOException e) { throw new RuntimeException(e); } } return vo; } @Override public JsonNode toJson() { return Json.toJson(this); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Long getOwnerUserId() { return ownerUserId; } public void setOwnerUserId(Long ownerUserId) { this.ownerUserId = ownerUserId; } public String getOwnerUsername() { return ownerUsername; } public void setOwnerUsername(String ownerUsername) { this.ownerUsername = ownerUsername; } public String getOwnerAvatar_70() { return ownerAvatar_70; } public void setOwnerAvatar_70(String ownerAvatar_70) { this.ownerAvatar_70 = ownerAvatar_70; } public String getOwnerJob() { return ownerJob; } public void setOwnerJob(String ownerJob) { this.ownerJob = ownerJob; } public String getOwnerCountry() { return ownerCountry; } public void setOwnerCountry(String ownerCountry) { this.ownerCountry = ownerCountry; } public Long getIndustryId() { return industryId; } public void setIndustryId(Long industryId) { this.industryId = industryId; } public String getIndustryName() { return industryName; } public void setIndustryName(String industryName) { this.industryName = industryName; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getInfo() { return info; } public void setInfo(String info) { this.info = info; } public String getBudget() { return budget; } public void setBudget(String budget) { this.budget = budget; } public String getCreateDate() { return createDate; } public void setCreateDate(String createDate) { this.createDate = createDate; } public List<String> getTags() { return tags; } public void setTags(List<String> tags) { this.tags = tags; } }