@Override public SiteEntity getByUUID(String uuid) throws EntityNotFoundException { Optional<SiteEntity> entityOptional = siteId2EntityMap.values().stream().filter((site) -> uuid.equals(site.getUuid())).findAny(); if (entityOptional.isPresent()) { return entityOptional.get(); } else { throw new EntityNotFoundException("Site with UUID: " + uuid + " not found"); } }
@Override public String toString() { return String.format("SiteEntity[siteId = %s, siteName =%s, description = %s, uuid = %s]", getSiteId(), getSiteName(), getDescription(), getUuid()); }
@Override public SiteEntity update(SiteEntity siteEntity) throws EntityNotFoundException { if (siteEntity.getSiteId() == null && siteEntity.getUuid() == null) { throw new IllegalArgumentException("siteId and UUID are both null, don't know how to update"); } SiteEntity oldEntity = (siteEntity.getSiteId() != null) ? getBySiteId(siteEntity.getSiteId()) : getByUUID(siteEntity.getUuid()); siteEntity.setUuid(oldEntity.getUuid()); siteEntity.setCreatedTime(oldEntity.getCreatedTime()); siteEntity.ensureDefault(); siteId2EntityMap.put(siteEntity.getSiteId(), siteEntity); return siteEntity; } }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public RESTResponse<SiteEntity> createSite(SiteEntity siteEntity) { return RESTResponse.<SiteEntity>async((builder) -> { SiteEntity entity = siteEntityService.create(siteEntity); builder.message("Successfully created site (siteId:" + entity.getSiteId() + ", uuid: " + entity.getUuid() + ")"); builder.data(entity); }).get(); }
@Override public SiteEntity update(SiteEntity siteEntity) throws EntityNotFoundException { if (siteEntity.getSiteId() == null && siteEntity.getUuid() == null) { throw new IllegalArgumentException("siteId and UUID are both null, don't know how to update"); } int result; try { SiteEntity oldEntity = getBySiteId(siteEntity.getSiteId()); siteEntity.setUuid(oldEntity.getUuid()); siteEntity.setCreatedTime(oldEntity.getCreatedTime()); siteEntity.ensureDefault(); result = queryService.update(updateSqlByUUID, siteEntity, new SiteEntityToRelation()); } catch (SQLException e) { LOGGER.error("Error to update SiteEntity: {}", siteEntity, e); throw new EntityNotFoundException(e); } if (result == 0) { throw new EntityNotFoundException("update " + siteEntity + "Not Found"); } return siteEntity; }
SiteEntity siteEntity = getUniqueSite(); siteResource.createSite(siteEntity); Assert.assertNotNull(siteEntity.getUuid()); ApplicationOperations.InstallOperation installOperation = new ApplicationOperations.InstallOperation(siteEntity.getSiteId(), appType, ApplicationEntity.Mode.LOCAL); installOperation.setConfiguration(appConfig);