How to convert Date to string in realm - java

I am developing app now I want to convert Date to String in realm but I have tried but I can't achieve what I want
below SaveMessage model class
#RealmClass
public class SaveMessage extends RealmObject {
private int mId;
private String mUsername;
private String mContent;
private Date mCreatedAt;
private boolean mRightMessage;
private String mPictureString;
private String mType;
public SaveMessage(int id, String username, String content, Date createdAt, boolean isRightMessage) {
mId = id;
mUsername = username;
mContent = content;
mCreatedAt = createdAt;
mRightMessage = isRightMessage;
}
public SaveMessage() {
}
public int getId() {
return mId;
}
public String getUsername() {
return mUsername;
}
public String getContent() {
return mContent;
}
public Date getDate() {
return mCreatedAt;
}
public void setDate(Date createdAt) {
mCreatedAt = createdAt;
}
below my Date conversion
SimpleDateFormat input = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); SimpleDateFormat
output = new SimpleDateFormat("dd/MM/yyyy");
Date d = new Date();
try {
d = input.parse(output);
} catch (ParseException e) {
e.printStackTrace();
}
public boolean ismRightMessage() {
return mRightMessage;
}
public int getmId() {
return mId;
}
public void setmId(int mId) {
this.mId = mId;
}
public String getmUsername() {
return mUsername;
}
public void setmUsername(String mUsername) {
this.mUsername = mUsername;
}
public String getmContent() {
return mContent;
}
public void setmContent(String mContent) {
this.mContent = mContent;
}
public boolean ismRightMessage(String isRightMessage) {
return mRightMessage;
}
public void setmRightMessage(boolean mRightMessage) {
this.mRightMessage = mRightMessage;
}
public String getPictureString() {
return mPictureString;
}
public void setPictureString(String pictureString) {
mPictureString = pictureString;
}
public String getType() {
return mType;
}
public void setType(String type) {
mType = type;
}
}

Related

Realm Migration is not working in Android?

I am at present working on a android chat application like whatsapp but I stuck at a situation in where Realm Migration is issue. I am not knowing so much about realm but testing it for a successful offline chat application. I am not able to use more than one model in realm because it is saying about the migrator. I tried all the ways but my migrator is not working and I also not having idea that what statements I have to use after this (schema.) statement for migrate my model according to my situations.
Here is the Code for my Realm ChatList Model:-
public class RealmChatListModel extends RealmObject {
#Index
private String userID;
private String Username;
private String Descryption;
private String phoneNo;
private String lastMessage;
private String Date;
private String ImageURI;
private long lastMessageTime;
public RealmChatListModel() {
}
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getUsername() {
return Username;
}
public void setUsername(String username) {
Username = username;
}
public String getDescryption() {
return Descryption;
}
public void setDescryption(String descryption) {
Descryption = descryption;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public String getLastMessage() {
return lastMessage;
}
public void setLastMessage(String lastMessage) {
this.lastMessage = lastMessage;
}
public String getDate() {
return Date;
}
public void setDate(String date) {
Date = date;
}
public String getImageURI() {
return ImageURI;
}
public void setImageURI(String imageURI) {
ImageURI = imageURI;
}
public long getLastMessageTime() {
return lastMessageTime;
}
public void setLastMessageTime(long lastMessageTime) {
this.lastMessageTime = lastMessageTime;
}
}
And here is my code for realm Chat Model :-
public class RealmChat extends RealmObject {
#PrimaryKey
#Index
private String messageKey;
private String time;
private String date;
private String textMessage;
private String type;
private String sender;
private String receiver;
private String uri;
private boolean isSeen;
private String duration;
private String receivername;
private String fileSize;
private boolean isNextDay;
private boolean isDeleted;
private Date extactdate;
private String repMesKey;
private String repMesUri;
private String repMesText;
private String repMesType;
private String repMesSender;
private long timestamp;
private String repMesSendPhone;
private boolean isReplied;
private String phoneNo;
private boolean isForwarded;
public String getMessageKey() {
return messageKey;
}
public void setMessageKey(String messageKey) {
this.messageKey = messageKey;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTextMessage() {
return textMessage;
}
public void setTextMessage(String textMessage) {
this.textMessage = textMessage;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public boolean isSeen() {
return isSeen;
}
public void setSeen(boolean seen) {
isSeen = seen;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public String getReceivername() {
return receivername;
}
public void setReceivername(String receivername) {
this.receivername = receivername;
}
public String getFileSize() {
return fileSize;
}
public void setFileSize(String fileSize) {
this.fileSize = fileSize;
}
public boolean isNextDay() {
return isNextDay;
}
public void setNextDay(boolean nextDay) {
isNextDay = nextDay;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
public Date getExtactdate() {
return extactdate;
}
public void setExtactdate(Date extactdate) {
this.extactdate = extactdate;
}
public String getRepMesKey() {
return repMesKey;
}
public void setRepMesKey(String repMesKey) {
this.repMesKey = repMesKey;
}
public String getRepMesUri() {
return repMesUri;
}
public void setRepMesUri(String repMesUri) {
this.repMesUri = repMesUri;
}
public String getRepMesText() {
return repMesText;
}
public void setRepMesText(String repMesText) {
this.repMesText = repMesText;
}
public String getRepMesType() {
return repMesType;
}
public void setRepMesType(String repMesType) {
this.repMesType = repMesType;
}
public String getRepMesSender() {
return repMesSender;
}
public void setRepMesSender(String repMesSender) {
this.repMesSender = repMesSender;
}
public String getRepMesSendPhone() {
return repMesSendPhone;
}
public void setRepMesSendPhone(String repMesSendPhone) {
this.repMesSendPhone = repMesSendPhone;
}
public boolean isReplied() {
return isReplied;
}
public void setReplied(boolean replied) {
isReplied = replied;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public boolean isForwarded() {
return isForwarded;
}
public void setForwarded(boolean forwarded) {
isForwarded = forwarded;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
And Here is my code for my migrator :-
public class RealmMigration implements io.realm.RealmMigration {
#Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
// Migrate from version 0 to version 1
if (oldVersion == 0) {
schema.get("RealmChatListModel")
.addField("Username", String.class)
.addRealmListField("lastMessageTime", long.class);
oldVersion++;
}
if (oldVersion == 1) {
schema.get("RealmChat")
.addField("extactdate", Date.class)
.addRealmListField("timestamp",long.class);
}
}
public static RealmConfiguration getDefaultConfig() {
return new RealmConfiguration.Builder()
.schemaVersion(2)
.migration(new RealmMigration())
.build();
}
#Override
public int hashCode() { return RealmMigration.class.hashCode(); }
#Override
public boolean equals(Object object) { return object != null && object instanceof RealmMigration; }
}
Please Help me...................................................................................
<<<<<<<<<<<<<<<<------------------(~~~~~~~~~~~~~~~~~~~)------------------->>>>>>>>>>>>>>>>>>>>>
Yes I got it my migration is working only by a single change :-
#Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
// Migrate from version 0 to version 1
if (oldVersion == 0) {
schema.get("RealmChatListModel")
.addField("userID", String.class, FieldAttribute.REQUIRED);
oldVersion++;
}
}
Here I removed Realm Chat from migrating the old version because it is the last model and added in realmChatListSchema that userID field is required.Noting else reqired. I am happy 🥰 🥰 🥰 .

How do I map Retrofit response to Data Model Class?

Here is my Retrofit Call...
public void getContests() {
String token = LoginActivity.authToken;
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(OctoInterface.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
OctoInterface api = retrofit.create(OctoInterface.class);
Call<List<OctoModel2>> call = api.getOctoContests(token);
call.enqueue(new Callback<List<OctoModel2>>() {
#Override
public void onResponse(Call<List<OctoModel2>> call, Response<List<OctoModel2>> response) {
int statusCode = response.code();
int i = 0;
if (response.body().size() > titleList.size()) {
for (i = 0; i <= response.body().size() -1; i++) {
contestIdList.add(String.valueOf(response.body().get(i).getId()));
titleList.add(response.body().get(i).getTitle());
subtitleList.add(response.body().get(i).getDescShort());
offerIdList.add(String.valueOf(response.body().get(i).getId()));
offerLogoList.add(response.body().get(i).getLogoUrl());
businessId = String.valueOf(response.body().get(i).getBusinessId());
submit_button_text = response.body().get(i).getSubmitButtonText();
}
}
}
#Override
public void onFailure(Call<List<OctoModel2>> call, Throwable t) {
Log.e("Get Contest failure", call.toString());
t.printStackTrace();
}
});
}
As you can see, I'm currently grabbing the pieces of the response that I need and passing them to individual array lists. I'd much rather pass the entire return into a list of model objects that hold the data.
Here is my POJO class for retrofit...
public class OctoModel2 {
#SerializedName("how_it_works")
#Expose
private List<String> howItWorks = null;
#SerializedName("id")
#Expose
private int id;
#SerializedName("business_id")
#Expose
private int businessId;
#SerializedName("title")
#Expose
private String title;
#SerializedName("desc_short")
#Expose
private String descShort;
#SerializedName("logo_url")
#Expose
private String logoUrl;
#SerializedName("hashtag")
#Expose
private String hashtag;
#SerializedName("confirm_message_title")
#Expose
private String confirmMessageTitle;
#SerializedName("rules")
#Expose
private String rules;
#SerializedName("confirm_message")
#Expose
private String confirmMessage;
#SerializedName("start_date")
#Expose
private String startDate;
#SerializedName("end_date")
#Expose
private String endDate;
#SerializedName("active")
#Expose
private boolean active;
#SerializedName("entry_count")
#Expose
private int entryCount;
#SerializedName("age_required")
#Expose
private int ageRequired;
#SerializedName("submit_button_text")
#Expose
private String submitButtonText;
#SerializedName("hide_redeem_code")
#Expose
private boolean hideRedeemCode;
#SerializedName("redeem_button_text")
#Expose
private String redeemButtonText;
#SerializedName("rules_text")
#Expose
private String rulesText;
#SerializedName("mode")
#Expose
private String mode;
#SerializedName("entry_mode")
#Expose
private String entryMode;
#SerializedName("created_at")
#Expose
private String createdAt;
#SerializedName("updated_at")
#Expose
private String updatedAt;
#SerializedName("deleted_at")
#Expose
private Object deletedAt;
#SerializedName("locations")
#Expose
private List<Location> locations = null;
#SerializedName("entries")
#Expose
private List<Entry> entries = null;
#SerializedName("entry")
#Expose
private Entry entry;
#SerializedName("AWSAccessKeyId")
#Expose
private String aWSAccessKeyId;
#SerializedName("key")
#Expose
private String key;
#SerializedName("policy")
#Expose
private String policy;
#SerializedName("signature")
#Expose
private String signature;
#SerializedName("uuid")
#Expose
private String uuid;
#SerializedName("reward")
#Expose
private Reward reward;
#SerializedName("s3_url")
#Expose
private String s3_url;
public OctoModel2(Integer id, Integer businessId, String title, String descShort, String logoUrl, String hashtag, String confirmMessageTitle, String rules, String confirmMessage, String startDate, String endDate, Boolean active,
String submitButtonText, String redeemButtonText, String rulesText, List<Location> locations, String aWSAccessKeyId, String key, String policy, String signature, String uuid) {
this.id = id;
this.businessId = businessId;
this.title = title;
this.descShort = descShort;
this.logoUrl = logoUrl;
this.hashtag = hashtag;
this.confirmMessageTitle = confirmMessageTitle;
this.rules = rules;
this.confirmMessage = confirmMessage;
this.startDate = startDate;
this.endDate = endDate;
this.active = active;
this.submitButtonText = submitButtonText;
this.redeemButtonText = redeemButtonText;
this.rulesText = rulesText;
this.locations = locations;
this.aWSAccessKeyId = aWSAccessKeyId;
this.key = key;
this.policy = policy;
this.signature = signature;
this.uuid = uuid;
}
public List<String> getHowItWorks() {
return howItWorks;
}
public void setHowItWorks(List<String> howItWorks) {
this.howItWorks = howItWorks;
}
public int getId() {
return id;
}
public List<OctoModel2> getResults() {
return results;
}
public void setId(int id) {
this.id = id;
}
public int getBusinessId() {
return businessId;
}
public void setBusinessId(int businessId) {
this.businessId = businessId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescShort() {
return descShort;
}
public void setDescShort(String descShort) {
this.descShort = descShort;
}
public String getLogoUrl() {
return logoUrl;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public String getHashtag() {
return hashtag;
}
public void setHashtag(String hashtag) {
this.hashtag = hashtag;
}
public String getConfirmMessageTitle() {
return confirmMessageTitle;
}
public void setConfirmMessageTitle(String confirmMessageTitle) {
this.confirmMessageTitle = confirmMessageTitle;
}
public String getRules() {
return rules;
}
public void setRules(String rules) {
this.rules = rules;
}
public String getConfirmMessage() {
return confirmMessage;
}
public void setConfirmMessage(String confirmMessage) {
this.confirmMessage = confirmMessage;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public int getEntryCount() {
return entryCount;
}
public void setEntryCount(int entryCount) {
this.entryCount = entryCount;
}
public int getAgeRequired() {
return ageRequired;
}
public void setAgeRequired(int ageRequired) {
this.ageRequired = ageRequired;
}
public String getSubmitButtonText() {
return submitButtonText;
}
public void setSubmitButtonText(String submitButtonText) {
this.submitButtonText = submitButtonText;
}
public boolean isHideRedeemCode() {
return hideRedeemCode;
}
public void setHideRedeemCode(boolean hideRedeemCode) {
this.hideRedeemCode = hideRedeemCode;
}
public String getRedeemButtonText() {
return redeemButtonText;
}
public void setRedeemButtonText(String redeemButtonText) {
this.redeemButtonText = redeemButtonText;
}
public String getRulesText() {
return rulesText;
}
public void setRulesText(String rulesText) {
this.rulesText = rulesText;
}
public String getMode() {
return mode;
}
public void setMode(String mode) {
this.mode = mode;
}
public String getEntryMode() {
return entryMode;
}
public void setEntryMode(String entryMode) {
this.entryMode = entryMode;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
public Object getDeletedAt() {
return deletedAt;
}
public void setDeletedAt(Object deletedAt) {
this.deletedAt = deletedAt;
}
public List<Location> getLocations() {
return locations;
}
public void setLocations(List<Location> locations) {
this.locations = locations;
}
public List<Entry> getEntries() {
return entries;
}
public void setEntries(List<Entry> entries) {
this.entries = entries;
}
public Entry getEntry() {
return entry;
}
public String getAWSAccessKeyId() {
return aWSAccessKeyId;
}
public void setAWSAccessKeyId(String aWSAccessKeyId) {
this.aWSAccessKeyId = aWSAccessKeyId;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getPolicy() {
return policy;
}
public void setPolicy(String policy) {
this.policy = policy;
}
public String getSignature() {
return signature;
}
public String gets3url() {
return s3_url;
}
public void setSignature(String signature) {
this.signature = signature;
}
public Reward getReward() {
return reward;
}
public void setReward(Reward reward) {
this.reward = reward;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
Instead of calling the data from each list like
TitleList.get(position);
SubtitleList.get(position);
LogoUrlList.get(position);
etc...
I'd like to be able to call
Contests.get(position).getTitle();
Contests.get(position).getSubtitle();
Contests.get(position).getLogoUrl();
or however it would be. This would make it better for me to sort the responses and get the data from individual responses without hoping and praying that I'm pulling the correct item from the correct ArrayList.
You need a mapper that maps your DTO (Data Transfer Object) into an entity or list of entities. For example:
public interface Mapper<From, To> {
To map(From value);
}
Now you can create a class, e.g. called `MyRetrofitResponseMapper, that implements the interface and maps the fields needed.
Moreover, you can create multiple mappers that map the same DTO into different entities depending on what DTO fields are required for those.
An example can be found here.

How to retrieve data from database based on date in java?

Here is what I have tried
Controller:
public void lovForFincurrency() {
LOG.info("\n\n\nINSIDE \n CLASS == LovController \n METHOD == lovForFincurrency(); ");
try {
apexManagerService = ServiceManagerFactory.getServiceManager(getServletContext());
MmsBean mmsBean = (MmsBean) getControllerObject(ApexManagedBean.MMSBEAN.getName(), MmsBean.class);
PmBean pmBean = (PmBean) getControllerObject(ApexManagedBean.PMBEAN.getName(), PmBean.class);
final FinCurrencyService finsurrencyservice = apexManagerService.getFinCurrencyService();
DateFormat dateFormat = new SimpleDateFormat("MM/DD/YYYY HH:mm:ss");
Date date = new Date();
List<Fincurrency> fincurrencies = finsurrencyservice.readcurrencies("Y", date);
List<Admlov> admlovs = new ArrayList<Admlov>();
for (Fincurrency fincurrency : fincurrencies) {
Admlov admlov = new Admlov();
admlov.setId(fincurrency.getCurrency());
admlov.setCode(fincurrency.getSymbol());
admlov.setDescr(fincurrency.getDescr());
admlovs.add(admlov);
}
if (admlovs != null) {
mmsBean.setAdmlovs(admlovs);
}
} catch (Exception ex) {
LOG.error(ex.getMessage(), ex);
addMessageToFacesContext(ERROR_DELETE);
}
LOG.info("EXITING THIS METHOD \n\n\n");
}
Here is my Repository:
public interface FinCurrencyRepo extends JpaRepository<Fincurrency, String> {
List<Fincurrency> findByEffectivefromAfterAndEffectivetoBeforeAndEnabled(Date sysdate, Date sysdate1,
String enabled);
}
Here is my serviceimplementation:
#Override
public List<Fincurrency> readcurrencies(String enabled, Date sysdate) {
return fincurrencyRepo.findByEffectivefromAfterAndEffectivetoBeforeAndEnabled(sysdate, sysdate, enabled);
}
Here is my Fincurrency Entity: I want to show symbol and currency in datatable of this year and after this year but not before this year. Kindly help me in this issue.
public class Fincurrency implements Serializable {
#Id
private String currency;
//#Temporal(TemporalType.DATE)
private Date effectivefrom;
//#Temporal(TemporalType.DATE)
private Date effectiveto;
private String enabled;
private String symbol;
#Column(name="\"TYPE\"")
private String type;
public Fincurrency() {
}
public String getCurrency() {
return this.currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
public BigDecimal getAfterdecimal() {
return this.afterdecimal;
}
public void setAfterdecimal(BigDecimal afterdecimal) {
this.afterdecimal = afterdecimal;
}
public Date getEffectivefrom() {
return this.effectivefrom;
}
public void setEffectivefrom(Date effectivefrom) {
this.effectivefrom = effectivefrom;
}
public Date getEffectiveto() {
return this.effectiveto;
}
public void setEffectiveto(Date effectiveto) {
this.effectiveto = effectiveto;
}
public String getEnabled() {
return this.enabled;
}
public void setEnabled(String enabled) {
this.enabled = enabled;
}
public String getSymbol() {
return this.symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
}

How to pass array of string in insert query in ibatis?

How to pass array of string in insert query statement in ibatis. On passing string array as parameter it is giving me this exception of ibatis -
Can't infer the SQL type to use for an instance of [Ljava.lang.String;. Use setObject() with an explicit Types value to specify the type to use.
How to solve this error ?
My method is -
public void insertCampaignData(String campaignData, ObjectMapper jsonObjMapper) {
Campaign campaign = null;
SqlSession session = null;
IfrmCreateCampaign createCampaign = null;
try {
campaign = jsonObjMapper.readValue(campaignData,Campaign.class);
session = DBConnectionFactory.getNewSession();
createCampaign = session.getMapper(IfrmCreateCampaign.class);
createCampaign.insertCampaignData(campaign);
} catch (Exception e) {
e.printStackTrace();
} finally {
session.close();
}
}
My entity class is -
import java.io.File;
import java.util.Date;
public class Campaign {
private long campaignId;
private String campaignName;
private long keywordId;
private String brandName;
private String clientName;
private String mobileNum;
private Date startTime;
private Date endTime;
private double campaignBudget;
private double allocatedFund;
private double campaignRate;
private boolean basicTgt;
private boolean customTgt;
private boolean advTgt;
private boolean chechme;
private boolean couponSend;
private String couponFrom;
private String couponTo;
private String couponFilePath;
private File[] couponFile;
private String[] couponFileFileName;
private String[] couponFileContent;
private String callbackUrl;
private String status;
private int campaignTypeId;
private long roAmount;
// edit
private int roType;
public int getRoType() {
return roType;
}
public void setRoType(int roType) {
this.roType = roType;
}
// edit
private String strStartTime;
private String strEndTime;
private String keyword;
private String keywordNum;
private int goal;
private double spentAmount;
private int goalAchievePercent;
private int dial;
private int uniqueDial;
private long userId;
private double campaignTotalAmount;
private double operatorShare;
private long responseCount;
private String strRoPdfFileName;
private File[] roPdf;
private String[] roPdfFileName;
private String[] roPdfContent;
public long getCampaignId() {
return campaignId;
}
public void setCampaignId(long campaignId) {
this.campaignId = campaignId;
}
public String getCampaignName() {
return campaignName;
}
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
public long getKeywordId() {
return keywordId;
}
public void setKeywordId(long keywordId) {
this.keywordId = keywordId;
}
public String getKeywordNum() {
return keywordNum;
}
public void setKeywordNum(String keywordNum) {
this.keywordNum = keywordNum;
}
public String getBrandName() {
return brandName;
}
public void setBrandName(String brandName) {
this.brandName = brandName;
}
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public String getMobileNum() {
return mobileNum;
}
public void setMobileNum(String mobileNum) {
this.mobileNum = mobileNum;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public double getCampaignBudget() {
return campaignBudget;
}
public void setCampaignBudget(double campaignBudget) {
this.campaignBudget = campaignBudget;
}
public double getAllocatedFund() {
return allocatedFund;
}
public void setAllocatedFund(double allocatedFund) {
this.allocatedFund = allocatedFund;
}
public double getCampaignRate() {
return campaignRate;
}
public void setCampaignRate(double campaignRate) {
this.campaignRate = campaignRate;
}
public boolean isBasicTgt() {
return basicTgt;
}
public void setBasicTgt(boolean basicTgt) {
this.basicTgt = basicTgt;
}
public boolean isCustomTgt() {
return customTgt;
}
public void setCustomTgt(boolean customTgt) {
this.customTgt = customTgt;
}
public boolean isAdvTgt() {
return advTgt;
}
public void setAdvTgt(boolean advTgt) {
this.advTgt = advTgt;
}
public boolean isChechme() {
return chechme;
}
public void setChechme(boolean chechme) {
this.chechme = chechme;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getStrStartTime() {
return strStartTime;
}
public void setStrStartTime(String strStartTime) {
this.strStartTime = strStartTime;
}
public String getStrEndTime() {
return strEndTime;
}
public void setStrEndTime(String strEndTime) {
this.strEndTime = strEndTime;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public int getGoal() {
return goal;
}
public void setGoal(int goal) {
this.goal = goal;
}
public double getSpentAmount() {
return spentAmount;
}
public void setSpentAmount(double spentAmount) {
this.spentAmount = spentAmount;
}
public int getGoalAchievePercent() {
return goalAchievePercent;
}
public void setGoalAchievePercent(int goalAchievePercent) {
this.goalAchievePercent = goalAchievePercent;
}
public int getDial() {
return dial;
}
public void setDial(int dial) {
this.dial = dial;
}
public int getUniqueDial() {
return uniqueDial;
}
public void setUniqueDial(int uniqueDial) {
this.uniqueDial = uniqueDial;
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public boolean isCouponSend() {
return couponSend;
}
public void setCouponSend(boolean couponSend) {
this.couponSend = couponSend;
}
public String getCouponFrom() {
return couponFrom;
}
public void setCouponFrom(String couponFrom) {
this.couponFrom = couponFrom;
}
public String getCouponTo() {
return couponTo;
}
public void setCouponTo(String couponTo) {
this.couponTo = couponTo;
}
public String getCouponFilePath() {
return couponFilePath;
}
public void setCouponFilePath(String couponFilePath) {
this.couponFilePath = couponFilePath;
}
public File[] getCouponFile() {
return couponFile;
}
public void setCouponFile(File[] couponFile) {
this.couponFile = couponFile;
}
public String[] getCouponFileFileName() {
return couponFileFileName;
}
public void setCouponFileFileName(String[] couponFileFileName) {
this.couponFileFileName = couponFileFileName;
}
public String[] getCouponFileContent() {
return couponFileContent;
}
public void setCouponFileContent(String[] couponFileContent) {
this.couponFileContent = couponFileContent;
}
public String getCallbackUrl() {
return callbackUrl;
}
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}
public int getCampaignTypeId() {
return campaignTypeId;
}
public void setCampaignTypeId(int campaignTypeId) {
this.campaignTypeId = campaignTypeId;
}
public long getRoAmount() {
return roAmount;
}
public void setRoAmount(long roAmount) {
this.roAmount = roAmount;
}
public double getOperatorShare() {
return operatorShare;
}
public void setOperatorShare(double operatorShare) {
this.operatorShare = operatorShare;
}
public long getResponseCount() {
return responseCount;
}
public void setResponseCount(long responseCount) {
this.responseCount = responseCount;
}
public double getCampaignTotalAmount() {
return campaignTotalAmount;
}
public void setCampaignTotalAmount(double campaignTotalAmount) {
this.campaignTotalAmount = campaignTotalAmount;
}
public String getStrRoPdfFileName() {
return strRoPdfFileName;
}
public void setStrRoPdfFileName(String strRoPdfFileName) {
this.strRoPdfFileName = strRoPdfFileName;
}
public File[] getRoPdf() {
return roPdf;
}
public void setRoPdf(File[] roPdf) {
this.roPdf = roPdf;
}
public String[] getRoPdfFileName() {
return roPdfFileName;
}
public void setRoPdfFileName(String[] roPdfFileName) {
this.roPdfFileName = roPdfFileName;
}
public String[] getRoPdfContent() {
return roPdfContent;
}
public void setRoPdfContent(String[] roPdfContent) {
this.roPdfContent = roPdfContent;
}
}
My xml mapping file is -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mogae.starStarWebServices.db.dao.IfrmCreateCampaign">
<insert id="insertCampaignData" statementType="PREPARED" >
insert into campaign(campaign_id,campaign_name,keyword_id,brand_name,client_name,mobile_num,start_time,end_time,campaign_type_id,ro_amount,ro_type,ro_pdf_file_name,campaign_budget,allocated_fund,campaign_rate,is_basic_tgt,is_custom_tgt,is_adv_tgt,is_checkme,is_coupon_send,coupon_from,coupon_to,coupon_file,callback_url,status) values (#{campaignId},#{campaignName},#{keywordId},#{brandName},#{clientName},#{mobileNum},#{startTime},#{endTime},#{campaignTypeId},#{roAmount},#{roType},
#{strRoPdfFileName},#{campaignBudget},#{allocatedFund},#{campaignRate},#{basicTgt},#{customTgt},#{advTgt},#{chechme},#{couponSend},#{couponFrom},#{couponTo},#{couponFileFileName},#{callbackUrl},#{status});
</insert>
<insert id="insertKeywordData" statementType="PREPARED" >
insert into keywords(keyword_id,keyword,keyword_num,booked_by,purchased_on,expires_on,status) values (#{keywordId},#{keyword},#{keywordNum},#{bookedBy},#{purchasedOn},#{expiresOn},#{status})
</insert>
</mapper>

How to use BeanUtils.copyProperties?

I am trying to copy properties from one bean to another. Here are the signature of two beans:
SearchContent:
public class SearchContent implements Serializable {
private static final long serialVersionUID = -4500094586165758427L;
private Integer id;
private String docName;
private String docType;
private String docTitle;
private String docAuthor;
private String securityGroup;
private String docAccount;
private Integer revLabel;
private String profile;
private LabelValueBean<String> workflowStage;
private Date createDate;
private Date inDate;
private String originalName;
private String format;
private String extension;
private Long fileSize;
private String author;
private LabelValueBean<String> entity;
private LabelValueBean<String> brand;
private LabelValueBean<String> product;
private LabelValueBean<String> collection;
private LabelValueBean<String> subCollection;
private String description;
private LabelValueBean<String> program;
private String vintage;
private String model;
private String restrictedZone;
private LabelValueBean<String> event;
private LabelValueBean<String> language;
private String geographicLocation;
private String watermark;
private Integer pageNumber;
private String summary;
private String agentName;
private String commissionedByName;
private String commissionedByDepartment;
private LabelValueBean<Integer> bestOf;
private String mediaLocation;
private LabelValueBean<Integer> fullRights;
private LabelValueBean<String> mediaUsage;
private Date rightsEndDate;
private String geographicRights;
private LabelValueBean<Integer> evinConformity;
private String contactReference;
private LabelValueBean<String> publicationScope;
private String rightsComment;
/**
* Constructor SearchContent
* #author TapasB
* #since 15-Oct-2013 - 5:45:55 pm
* #version DAM 1.0
*/
public SearchContent() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDocName() {
return docName;
}
public void setDocName(String docName) {
this.docName = docName;
}
public String getDocType() {
return docType;
}
public void setDocType(String docType) {
this.docType = docType;
}
public String getDocTitle() {
return docTitle;
}
public void setDocTitle(String docTitle) {
this.docTitle = docTitle;
}
public String getDocAuthor() {
return docAuthor;
}
public void setDocAuthor(String docAuthor) {
this.docAuthor = docAuthor;
}
public String getSecurityGroup() {
return securityGroup;
}
public void setSecurityGroup(String securityGroup) {
this.securityGroup = securityGroup;
}
public String getDocAccount() {
return docAccount;
}
public void setDocAccount(String docAccount) {
this.docAccount = docAccount;
}
public Integer getRevLabel() {
return revLabel;
}
public void setRevLabel(Integer revLabel) {
this.revLabel = revLabel;
}
public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
public LabelValueBean<String> getWorkflowStage() {
return workflowStage;
}
public void setWorkflowStage(LabelValueBean<String> workflowStage) {
this.workflowStage = workflowStage;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getInDate() {
return inDate;
}
public void setInDate(Date inDate) {
this.inDate = inDate;
}
public String getOriginalName() {
return originalName;
}
public void setOriginalName(String originalName) {
this.originalName = originalName;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public String getExtension() {
return extension;
}
public void setExtension(String extension) {
this.extension = extension;
}
public Long getFileSize() {
return fileSize;
}
public void setFileSize(Long fileSize) {
this.fileSize = fileSize;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public LabelValueBean<String> getEntity() {
return entity;
}
public void setEntity(LabelValueBean<String> entity) {
this.entity = entity;
}
public LabelValueBean<String> getBrand() {
return brand;
}
public void setBrand(LabelValueBean<String> brand) {
this.brand = brand;
}
public LabelValueBean<String> getProduct() {
return product;
}
public void setProduct(LabelValueBean<String> product) {
this.product = product;
}
public LabelValueBean<String> getCollection() {
return collection;
}
public void setCollection(LabelValueBean<String> collection) {
this.collection = collection;
}
public LabelValueBean<String> getSubCollection() {
return subCollection;
}
public void setSubCollection(LabelValueBean<String> subCollection) {
this.subCollection = subCollection;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public LabelValueBean<String> getProgram() {
return program;
}
public void setProgram(LabelValueBean<String> program) {
this.program = program;
}
public String getVintage() {
return vintage;
}
public void setVintage(String vintage) {
this.vintage = vintage;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getRestrictedZone() {
return restrictedZone;
}
public void setRestrictedZone(String restrictedZone) {
this.restrictedZone = restrictedZone;
}
public LabelValueBean<String> getEvent() {
return event;
}
public void setEvent(LabelValueBean<String> event) {
this.event = event;
}
public LabelValueBean<String> getLanguage() {
return language;
}
public void setLanguage(LabelValueBean<String> language) {
this.language = language;
}
public String getGeographicLocation() {
return geographicLocation;
}
public void setGeographicLocation(String geographicLocation) {
this.geographicLocation = geographicLocation;
}
public String getWatermark() {
return watermark;
}
public void setWatermark(String watermark) {
this.watermark = watermark;
}
public Integer getPageNumber() {
return pageNumber;
}
public void setPageNumber(Integer pageNumber) {
this.pageNumber = pageNumber;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getAgentName() {
return agentName;
}
public void setAgentName(String agentName) {
this.agentName = agentName;
}
public String getCommissionedByName() {
return commissionedByName;
}
public void setCommissionedByName(String commissionedByName) {
this.commissionedByName = commissionedByName;
}
public String getCommissionedByDepartment() {
return commissionedByDepartment;
}
public void setCommissionedByDepartment(String commissionedByDepartment) {
this.commissionedByDepartment = commissionedByDepartment;
}
public LabelValueBean<Integer> getBestOf() {
return bestOf;
}
public void setBestOf(LabelValueBean<Integer> bestOf) {
this.bestOf = bestOf;
}
public String getMediaLocation() {
return mediaLocation;
}
public void setMediaLocation(String mediaLocation) {
this.mediaLocation = mediaLocation;
}
public LabelValueBean<Integer> getFullRights() {
return fullRights;
}
public void setFullRights(LabelValueBean<Integer> fullRights) {
this.fullRights = fullRights;
}
public LabelValueBean<String> getMediaUsage() {
return mediaUsage;
}
public void setMediaUsage(LabelValueBean<String> mediaUsage) {
this.mediaUsage = mediaUsage;
}
public Date getRightsEndDate() {
return rightsEndDate;
}
public void setRightsEndDate(Date rightsEndDate) {
this.rightsEndDate = rightsEndDate;
}
public String getGeographicRights() {
return geographicRights;
}
public void setGeographicRights(String geographicRights) {
this.geographicRights = geographicRights;
}
public LabelValueBean<Integer> getEvinConformity() {
return evinConformity;
}
public void setEvinConformity(LabelValueBean<Integer> evinConformity) {
this.evinConformity = evinConformity;
}
public String getContactReference() {
return contactReference;
}
public void setContactReference(String contactReference) {
this.contactReference = contactReference;
}
public LabelValueBean<String> getPublicationScope() {
return publicationScope;
}
public void setPublicationScope(LabelValueBean<String> publicationScope) {
this.publicationScope = publicationScope;
}
public String getRightsComment() {
return rightsComment;
}
public void setRightsComment(String rightsComment) {
this.rightsComment = rightsComment;
}
}
And Content:
public class Content implements Serializable {
private static final long serialVersionUID = 2999449587418137835L;
private Boolean selected;
private Boolean renditionInfoFetched;
private String searchPageImageRendition;
private String detailPageImageRendition;
private String videoRendition;
private Integer id;
private String docName;
private String docType;
private String docTitle;
private String docAuthor;
private String securityGroup;
private String docAccount;
private Integer revLabel;
private String profile;
private Date createDate;
private Date inDate;
private String originalName;
private String format;
private String extension;
private Long fileSize;
private String author;
private LabelValueBean<String> entity;
private LabelValueBean<String> brand;
private LabelValueBean<String> product;
private LabelValueBean<String> collection;
private LabelValueBean<String> subCollection;
private String description;
private LabelValueBean<String> program;
private String vintage;
private String model;
private String restrictedZone;
private LabelValueBean<String> event;
private LabelValueBean<String> language;
private String geographicLocation;
private String watermark;
private Integer pageNumber;
private String summary;
private String agentName;
private String commissionedByName;
private String commissionedByDepartment;
private LabelValueBean<Integer> bestOf;
private String mediaLocation;
private LabelValueBean<Integer> fullRights;
private LabelValueBean<String> mediaUsage;
private Date rightsEndDate;
private String geographicRights;
private LabelValueBean<Integer> evinConformity;
private String contactReference;
private LabelValueBean<String> publicationScope;
private String rightsComment;
public Boolean getSelected() {
return selected;
}
public void setSelected(Boolean selected) {
this.selected = selected;
}
public Boolean getRenditionInfoFetched() {
return renditionInfoFetched;
}
public void setRenditionInfoFetched(Boolean renditionInfoFetched) {
this.renditionInfoFetched = renditionInfoFetched;
}
public String getSearchPageImageRendition() {
return searchPageImageRendition;
}
public void setSearchPageImageRendition(String searchPageImageRendition) {
this.searchPageImageRendition = searchPageImageRendition;
}
public String getDetailPageImageRendition() {
return detailPageImageRendition;
}
public void setDetailPageImageRendition(String detailPageImageRendition) {
this.detailPageImageRendition = detailPageImageRendition;
}
public String getVideoRendition() {
return videoRendition;
}
public void setVideoRendition(String videoRendition) {
this.videoRendition = videoRendition;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDocName() {
return docName;
}
public void setDocName(String docName) {
this.docName = docName;
}
public String getDocType() {
return docType;
}
public void setDocType(String docType) {
this.docType = docType;
}
public String getDocTitle() {
return docTitle;
}
public void setDocTitle(String docTitle) {
this.docTitle = docTitle;
}
public String getDocAuthor() {
return docAuthor;
}
public void setDocAuthor(String docAuthor) {
this.docAuthor = docAuthor;
}
public String getSecurityGroup() {
return securityGroup;
}
public void setSecurityGroup(String securityGroup) {
this.securityGroup = securityGroup;
}
public String getDocAccount() {
return docAccount;
}
public void setDocAccount(String docAccount) {
this.docAccount = docAccount;
}
public Integer getRevLabel() {
return revLabel;
}
public void setRevLabel(Integer revLabel) {
this.revLabel = revLabel;
}
public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getInDate() {
return inDate;
}
public void setInDate(Date inDate) {
this.inDate = inDate;
}
public String getOriginalName() {
return originalName;
}
public void setOriginalName(String originalName) {
this.originalName = originalName;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public String getExtension() {
return extension;
}
public void setExtension(String extension) {
this.extension = extension;
}
public Long getFileSize() {
return fileSize;
}
public void setFileSize(Long fileSize) {
this.fileSize = fileSize;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public LabelValueBean<String> getEntity() {
return entity;
}
public void setEntity(LabelValueBean<String> entity) {
this.entity = entity;
}
public LabelValueBean<String> getBrand() {
return brand;
}
public void setBrand(LabelValueBean<String> brand) {
this.brand = brand;
}
public LabelValueBean<String> getProduct() {
return product;
}
public void setProduct(LabelValueBean<String> product) {
this.product = product;
}
public LabelValueBean<String> getCollection() {
return collection;
}
public void setCollection(LabelValueBean<String> collection) {
this.collection = collection;
}
public LabelValueBean<String> getSubCollection() {
return subCollection;
}
public void setSubCollection(LabelValueBean<String> subCollection) {
this.subCollection = subCollection;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public LabelValueBean<String> getProgram() {
return program;
}
public void setProgram(LabelValueBean<String> program) {
this.program = program;
}
public String getVintage() {
return vintage;
}
public void setVintage(String vintage) {
this.vintage = vintage;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getRestrictedZone() {
return restrictedZone;
}
public void setRestrictedZone(String restrictedZone) {
this.restrictedZone = restrictedZone;
}
public LabelValueBean<String> getEvent() {
return event;
}
public void setEvent(LabelValueBean<String> event) {
this.event = event;
}
public LabelValueBean<String> getLanguage() {
return language;
}
public void setLanguage(LabelValueBean<String> language) {
this.language = language;
}
public String getGeographicLocation() {
return geographicLocation;
}
public void setGeographicLocation(String geographicLocation) {
this.geographicLocation = geographicLocation;
}
public String getWatermark() {
return watermark;
}
public void setWatermark(String watermark) {
this.watermark = watermark;
}
public Integer getPageNumber() {
return pageNumber;
}
public void setPageNumber(Integer pageNumber) {
this.pageNumber = pageNumber;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getAgentName() {
return agentName;
}
public void setAgentName(String agentName) {
this.agentName = agentName;
}
public String getCommissionedByName() {
return commissionedByName;
}
public void setCommissionedByName(String commissionedByName) {
this.commissionedByName = commissionedByName;
}
public String getCommissionedByDepartment() {
return commissionedByDepartment;
}
public void setCommissionedByDepartment(String commissionedByDepartment) {
this.commissionedByDepartment = commissionedByDepartment;
}
public LabelValueBean<Integer> getBestOf() {
return bestOf;
}
public void setBestOf(LabelValueBean<Integer> bestOf) {
this.bestOf = bestOf;
}
public String getMediaLocation() {
return mediaLocation;
}
public void setMediaLocation(String mediaLocation) {
this.mediaLocation = mediaLocation;
}
public LabelValueBean<Integer> getFullRights() {
return fullRights;
}
public void setFullRights(LabelValueBean<Integer> fullRights) {
this.fullRights = fullRights;
}
public LabelValueBean<String> getMediaUsage() {
return mediaUsage;
}
public void setMediaUsage(LabelValueBean<String> mediaUsage) {
this.mediaUsage = mediaUsage;
}
public Date getRightsEndDate() {
return rightsEndDate;
}
public void setRightsEndDate(Date rightsEndDate) {
this.rightsEndDate = rightsEndDate;
}
public String getGeographicRights() {
return geographicRights;
}
public void setGeographicRights(String geographicRights) {
this.geographicRights = geographicRights;
}
public LabelValueBean<Integer> getEvinConformity() {
return evinConformity;
}
public void setEvinConformity(LabelValueBean<Integer> evinConformity) {
this.evinConformity = evinConformity;
}
public String getContactReference() {
return contactReference;
}
public void setContactReference(String contactReference) {
this.contactReference = contactReference;
}
public LabelValueBean<String> getPublicationScope() {
return publicationScope;
}
public void setPublicationScope(LabelValueBean<String> publicationScope) {
this.publicationScope = publicationScope;
}
public String getRightsComment() {
return rightsComment;
}
public void setRightsComment(String rightsComment) {
this.rightsComment = rightsComment;
}
}
I am trying to copy properties from SearchContent to Content as:
Content content = new Content();
Converter converter = new DateConverter(null);
BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
beanUtilsBean.getConvertUtils().register(converter, Date.class);
BeanUtils.copyProperties(searchContent, content);
System.out.println(searchContent);
System.out.println(content);
The Sysout is printing:
com.mhis.dam.service.search.bean.SearchContent[id=52906,docName=MHIS043570,docType=Images,docTitle=preview_1_8,docAuthor=sysadmin,securityGroup=Internal,docAccount=WF/017/DAM/000,revLabel=1,profile=DAMMedia,workflowStage=com.mhis.dam.generic.bean.LabelValueBean[label=Published,value=published],createDate=Fri Oct 18 15:30:35 IST 2013,inDate=Fri Oct 18 15:30:35 IST 2013,originalName=Vintage 2004 Gift Box & Bottle Black - hires.jpg,format=image/jpeg,extension=jpg,fileSize=2106898,author=Arjan,entity=com.mhis.dam.generic.bean.LabelValueBean[label=Dom Perignon,value=WF/017/DAM],brand=com.mhis.dam.generic.bean.LabelValueBean[label=Dom Perignon,value=WF/017/DAM/001],product=com.mhis.dam.generic.bean.LabelValueBean[label=Blanc,value=17_1_blanc],collection=com.mhis.dam.generic.bean.LabelValueBean[label=Pack shot,value=pack_shot_dp],subCollection=com.mhis.dam.generic.bean.LabelValueBean[label=Bottle shot,value=ps_bottle_dp],description=preview_1,program=com.mhis.dam.generic.bean.LabelValueBean[label=<null>,value=],vintage=,model=,restrictedZone=,event=com.mhis.dam.generic.bean.LabelValueBean[label=<null>,value=],language=com.mhis.dam.generic.bean.LabelValueBean[label=<null>,value=],geographicLocation=,watermark=,pageNumber=0,summary=,agentName=,commissionedByName=Nicolas,commissionedByDepartment=,bestOf=com.mhis.dam.generic.bean.LabelValueBean[label=<null>,value=0],mediaLocation=,fullRights=com.mhis.dam.generic.bean.LabelValueBean[label=<null>,value=1],mediaUsage=com.mhis.dam.generic.bean.LabelValueBean[label=<null>,value=],rightsEndDate=<null>,geographicRights=,evinConformity=com.mhis.dam.generic.bean.LabelValueBean[label=<null>,value=2],contactReference=,publicationScope=com.mhis.dam.generic.bean.LabelValueBean[label=Full public usage,value=fullPublic],rightsComment=]
com.mhis.dam.web.model.Content[selected=<null>,renditionInfoFetched=<null>,searchPageImageRendition=<null>,detailPageImageRendition=<null>,videoRendition=<null>,id=<null>,docName=<null>,docType=<null>,docTitle=<null>,docAuthor=<null>,securityGroup=<null>,docAccount=<null>,revLabel=<null>,profile=<null>,createDate=<null>,inDate=<null>,originalName=<null>,format=<null>,extension=<null>,fileSize=<null>,author=<null>,entity=<null>,brand=<null>,product=<null>,collection=<null>,subCollection=<null>,description=<null>,program=<null>,vintage=<null>,model=<null>,restrictedZone=<null>,event=<null>,language=<null>,geographicLocation=<null>,watermark=<null>,pageNumber=<null>,summary=<null>,agentName=<null>,commissionedByName=<null>,commissionedByDepartment=<null>,bestOf=<null>,mediaLocation=<null>,fullRights=<null>,mediaUsage=<null>,rightsEndDate=<null>,geographicRights=<null>,evinConformity=<null>,contactReference=<null>,publicationScope=<null>,rightsComment=<null>]
It is obvious to have null values for selected and renditionInfoFetched fields of the class Content, since they are not present in SearchContent but you can see all the other properties of Content is null. I am unable to find what I am doing wrong!
Any pointer would be very helpful.
There are two BeanUtils.copyProperties(parameter1, parameter2) in Java.
One is
org.apache.commons.beanutils.BeanUtils.copyProperties(Object dest,
Object orig)
Another is
org.springframework.beans.BeanUtils.copyProperties(Object source,
Object target)
Pay attention to the opposite position of parameters.
If you want to copy from searchContent to content, then code should be as follows
BeanUtils.copyProperties(content, searchContent);
You need to reverse the parameters as above in your code.
From API,
public static void copyProperties(Object dest, Object orig)
throws IllegalAccessException,
InvocationTargetException)
Parameters:
dest - Destination bean whose properties are modified
orig - Origin bean whose properties are retrieved
As you can see in the below source code, BeanUtils.copyProperties internally uses reflection and there's additional internal cache lookup steps as well which is going to add cost wrt performance
private static void copyProperties(Object source, Object target, #Nullable Class<?> editable,
#Nullable String... ignoreProperties) throws BeansException {
Assert.notNull(source, "Source must not be null");
Assert.notNull(target, "Target must not be null");
Class<?> actualEditable = target.getClass();
if (editable != null) {
if (!editable.isInstance(target)) {
throw new IllegalArgumentException("Target class [" + target.getClass().getName() +
"] not assignable to Editable class [" + editable.getName() + "]");
}
actualEditable = editable;
}
**PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);**
List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null);
for (PropertyDescriptor targetPd : targetPds) {
Method writeMethod = targetPd.getWriteMethod();
if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) {
PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
if (sourcePd != null) {
Method readMethod = sourcePd.getReadMethod();
if (readMethod != null &&
ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) {
try {
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
readMethod.setAccessible(true);
}
Object value = readMethod.invoke(source);
if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
writeMethod.setAccessible(true);
}
writeMethod.invoke(target, value);
}
catch (Throwable ex) {
throw new FatalBeanException(
"Could not copy property '" + targetPd.getName() + "' from source to target", ex);
}
}
}
}
}
}
So it's better to use plain setters given the cost reflection

Categories

Resources