Item implements Serializable, Cacheable { public static Item fromJSON(String json) { Item node; Gson gson = GsonUtil.getSubtreeGson(); node = gson.fromJson(json, Item.class); if (node.getId() == null || StringUtils.isBlank(node.getId())) { node.setId(IdGenerator.generate()); } return node; }  @Id String getId(); void setId(String id); @Enumerated(EnumType.STRING) @Column(name = ITEM_TYPE) ItemType getItemType(); void setItemType(ItemType itemType); @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(columnDefinition = "bbox_id") Bbox getBbox(); void setBbox(Bbox bbox); @Column(name = "name", length = NAME_MAX_LENGTH) String getName(); void setName(String name); @Enumerated(EnumType.STRING) Item.Type getType(); void setType(Item.Type type); @Column(name = "attr", length = ATTR_MAX_LENGTH) String getAttr(); void setAttr(String attr); boolean isRibbonable(); void setRibbonable(boolean ribbonable); @Column(name = "show_children") boolean isShowChildren(); void setShowChildren(boolean showChildren); boolean isEnabled(); void setEnabled(boolean enabled); @OneToOne(cascade = CascadeType.ALL) @JoinColumn(columnDefinition = "summary_id") Summary getSummary(); void setSummary(Summary summary); @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true) @JoinTable(name = "service_item", joinColumns = { @JoinColumn(name = "item_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "service_id", referencedColumnName = "id") }) @IndexColumn(name = "list_index") List<Service> getServices(); void setServices(List<Service> services); @ManyToMany(fetch = FetchType.LAZY) @LazyCollection(LazyCollectionOption.EXTRA) @JoinTable( name = "aggregation_children", joinColumns = { @JoinColumn(name = "aggregation_id", referencedColumnName = "id")}, inverseJoinColumns = { @JoinColumn(name = "item_id", referencedColumnName = "id")}) @IndexColumn(name = "list_index") List<Item> getChildren(); List<String> proxiedChildren(); void setChildren(List<Item> children); @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "displayed_children", joinColumns = @JoinColumn(name = "item_id")) @IndexColumn(name = "list_index") @Column(name = "child_id") List<String> getDisplayedChildren(); @Temporal(TemporalType.TIMESTAMP) @Column(name = "last_update") @Override Date getLastModified(); void setLastModified(Date timestamp); @Column(name="active_storm") boolean isActiveStorm(); void setActiveStorm(boolean isActiveStorm); boolean isFeatured(); void setFeatured(boolean featured); void setDisplayedChildren(List<String> displayedChildren); String toJSON(boolean subtree); static Item fromJSON(String json); static Item copyValues(final Item from, final Item to); Item instantiateTemplate(List<Service> withServices); WMSService fetchWmsService(); WFSService fetchWfsService(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final String UBER_ID; static final int NAME_MAX_LENGTH; static final int ATTR_MAX_LENGTH; static final String ITEM_TYPE; static final String DATA_TYPE; static final String AGGREGATION_TYPE; }
@Test @Ignore public void testDB() throws SessionIOException, CycleIntroductionException { ItemManager manager = new ItemManager(); String id; Item fromJSON = Item.fromJSON(itemJSON); id = manager.persist(fromJSON); assertNotNull(id); Item item = manager.load(id); assertNotNull(item); }
@Test public void testFromJSON() { Item item = Item.fromJSON(itemJSON); assertThat(item.getId(), is(equalTo("abc123"))); }