@Override public HomePage map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { HomePage homePage = new HomePage(); homePage.setId((UUID) resultSet.getObject("id")); if (!Strings.isNullOrEmpty(resultSet.getString("localization_data"))) { ObjectMapper mapper = new ObjectMapper(); try { Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap(); Map[] data = mapper.readValue(resultSet.getString("localization_data"), Map[].class); for (Map map : data) { localizedVersions.put(LocaleUtils.toLocale((String) map.get("locale")), (Map) map.get("entity")); } homePage.setLocalizedVersions(localizedVersions); } catch (IOException e) { throw new SQLException("Failed to de-serialize localization JSON data", e); } } return homePage; } }
public HomePage create(@Valid HomePage homePage) throws EntityAlreadyExistsException, InvalidEntityException { if (this.dao.findBySlug(HOME_PAGE_TYPE, homePage.getSlug(), getTenant()) != null) { throw new EntityAlreadyExistsException(); } this.dao.begin(); UUID entityId = UUID.randomUUID(); homePage.setId(entityId); this.dao.createEntity(homePage, HOME_PAGE_TYPE, getTenant()); this.dao.createOrUpdateAddons(homePage); this.dao.commit(); return homePage; }
public void update(@Valid HomePage entity) throws EntityDoesNotExistException, InvalidEntityException { this.dao.begin(); HomePage homePage = find(); if (homePage == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } getObservationManager().notify(new EntityUpdatingEvent(), entity); entity.setId(homePage.getId()); this.dao.createOrUpdateAddons(entity); this.dao.commit(); getObservationManager().notify(new EntityUpdatedEvent(), entity); }
public HomePage getOrCreate(HomePage homePage) throws InvalidEntityException { HomePage original; this.dao.begin(); original = this.find(); if (original != null) { this.dao.commit(); return original; } getObservationManager().notify(new EntityCreatingEvent(), homePage); UUID entityId = UUID.randomUUID(); homePage.setId(entityId); this.dao.createEntityIfItDoesNotExist(homePage, HOME_PAGE_TYPE, getTenant()); this.dao.commit(); getObservationManager().notify(new EntityCreatedEvent(), homePage); return this.find(); }