public static Entry infoToEntry(PartData info) { EntryType type = info.getType(); Entry entry; switch (type) { case PLASMID: entry = setPlasmidFields(info.getPlasmidData(), new Plasmid()); break; case STRAIN: entry = setStrainFields(info.getStrainData(), new Strain()); break; case ARABIDOPSIS: entry = setSeedFields(info.getArabidopsisSeedData(), new ArabidopsisSeed()); break; case PART: default: entry = new Part(); break; } if (entry == null) return null; // common fields if (StringUtils.isEmpty(info.getRecordId())) entry.setRecordId(UUID.randomUUID().toString()); else entry.setRecordId(info.getRecordId()); entry.setVersionId(entry.getRecordId()); if (info.getCreationTime() == 0) entry.setCreationTime(new Date()); else entry.setCreationTime(new Date(info.getCreationTime())); entry.setModificationTime(entry.getCreationTime()); entry = setCommon(entry, info); return entry; }
/** * sets the corresponding fields in data only if they are not null * * @param data PartData object to converted to Entry * @param entry if null, a new entry is created otherwise entry is used * @return converted PartData object */ public static Entry updateEntryField(PartData data, Entry entry) { EntryType type = data.getType(); if (type == null) return entry; switch (type) { case PLASMID: entry = setPlasmidFields(data.getPlasmidData(), entry); break; case STRAIN: entry = setStrainFields(data.getStrainData(), entry); break; case PART: break; case ARABIDOPSIS: entry = setSeedFields(data.getArabidopsisSeedData(), entry); break; } entry = setCommon(entry, data); return entry; }