public void removeAllInstances() throws NotFoundServiceEx { List<GSInstance> list = instanceAdminService.getAll(); for (GSInstance item : list) { LOGGER.warn("Removing " + item); boolean ret = instanceAdminService.delete(item.getId()); if ( !ret ) { LOGGER.error("Could not remove " + item); } } long count = instanceAdminService.getCount(null); if ( count > 0 ) { LOGGER.error("Items not removed"); } }
@Override public RESTOutputInstance get(String name) throws NotFoundRestEx, InternalErrorRestEx { try { GSInstance ret = instanceAdminService.get(name); return toOutputInstance(ret); } catch (NotFoundServiceEx ex) { LOGGER.warn("GSInstance not found: " + name); throw new NotFoundRestEx("GSInstance not found: " + name); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }
@Override public RESTShortInstanceList getList(String nameLike, Integer page, Integer entries) { List<ShortInstance> list = instanceAdminService.getList(nameLike, page, entries); return new RESTShortInstanceList(list); }
try { remote_instance = geofenceRemoteService .getInstanceAdminService().get(instance.getId()); remote_instance.setName(instance.getName()); remote_instance.setDateCreation(instance.getDateCreation()); remote_instance.setPassword(instance.getPassword()); remote_instance.setUsername(instance.getUsername()); geofenceRemoteService.getInstanceAdminService().update( remote_instance); } catch (NotFoundServiceEx e) { remote_instance.setPassword(instance.getPassword()); remote_instance.setUsername(instance.getUsername()); geofenceRemoteService.getInstanceAdminService().insert( remote_instance); } catch (Exception e) {
public void deleteInstance(GSInstanceModel instance) { org.geoserver.geofence.core.model.GSInstance remote_instance = null; try { remote_instance = geofenceRemoteService.getInstanceAdminService() .get(instance.getId()); geofenceRemoteService.getInstanceAdminService().delete( remote_instance.getId()); } catch (NotFoundServiceEx e) { logger.error(e.getLocalizedMessage(), e.getCause()); throw new ApplicationException(e.getLocalizedMessage(), e.getCause()); } }
/** * Simplified operation used for quick re-insertion of data extracted with a GET op in the related service */ @Override public void setInstances(RESTShortInstanceList instances) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { int okCnt = 0; for (ShortInstance si : instances) { LOGGER.info("Adding instance " +si ); try { GSInstance i = new GSInstance(); i.setName(si.getName()); i.setDescription(si.getDescription()); i.setBaseURL(si.getUrl()); i.setUsername("unknown"); i.setPassword("unknown"); instanceAdminService.insert(i); okCnt++; } catch (Exception e) { LOGGER.info("Could not add instance " +si +": " + e.getMessage()); } } LOGGER.info(okCnt+"/"+instances.getList().size() + " items inserted"); }
@Override public long count(String nameLike) { return instanceAdminService.getCount(nameLike); }
@Override public Response delete(Long id, boolean cascade) throws ConflictRestEx, NotFoundRestEx, InternalErrorRestEx { try { if ( cascade ) { ruleAdminService.deleteRulesByInstance(id); } else { RuleFilter filter = new RuleFilter(SpecialFilterType.ANY); filter.setInstance(id); filter.getInstance().setIncludeDefault(false); long cnt = ruleAdminService.count(filter); if ( cnt > 0 ) { throw new ConflictRestEx("Existing rules reference the GSInstance " + id); } } if ( ! instanceAdminService.delete(id)) { LOGGER.warn("GSInstance not found: " + id); throw new NotFoundRestEx("GSInstance not found: " + id); } return Response.status(Status.OK).entity("OK\n").build(); } catch (GeoFenceRestEx ex) { // already handled throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("GSInstance not found: " + id); throw new NotFoundRestEx("GSInstance not found: " + id); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }
protected RESTBatch collectInstances(RESTBatch backup) { for (GSInstance instance : instanceAdminService.getFullList(null, null, null)) { RESTBatchOperation op = RESTBatchOperationFactory.createInstanceInputOp(); RESTInputInstance input = new RESTInputInstance(); op.setPayload(input); input.setBaseURL(instance.getBaseURL()); input.setDescription(instance.getDescription()); input.setName(instance.getName()); input.setPassword(instance.getPassword()); input.setUsername(instance.getUsername()); backup.add(op); } return backup; }
instance.setId(null); long newId = instanceAdminService.insert(instance); LOGGER.info("Remapping gsInstance " + oldId + " -> " + newId); remap.getInstances().put(oldId, newId);
/** * @deprecated misbehaves since usergroups introduction. Please use backup() */ @Override public RESTFullConfiguration getConfiguration(Boolean includeGRUsers) { RESTFullConfiguration cfg = new RESTFullConfiguration(); RESTFullUserList users = new RESTFullUserList(); List<GSUser> userlist = userAdminService.getFullList(null, null, null); for (GSUser user : userlist) { user.setGroups(userAdminService.getFull(user.getName()).getGroups()); } users.setList(userlist); cfg.setUserList(users); RESTFullUserGroupList profiles = new RESTFullUserGroupList(); profiles.setList(userGroupAdminService.getList(null, null, null)); cfg.setUserGroupList(profiles); RESTFullGSInstanceList instances = new RESTFullGSInstanceList(); instances.setList(instanceAdminService.getFullList(null, null, null)); cfg.setGsInstanceList(instances); RESTFullRuleList rules = new RESTFullRuleList(); rules.setList(ruleAdminService.getListFull(null, null, null)); cfg.setRuleList(rules); if ( includeGRUsers ) { RESTFullGRUserList grUsers = new RESTFullGRUserList(); grUsers.setList(grUserAdminService.getFullList(null, null, null)); cfg.setGrUserList(grUsers); } return cfg; }
@Override public RESTOutputInstance get(Long id) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { try { GSInstance ret = instanceAdminService.get(id); return toOutputInstance(ret); } catch (NotFoundServiceEx ex) { LOGGER.warn("GSInstance not found: " + id); throw new NotFoundRestEx("GSInstance not found: " + id); } catch (Exception ex) { LOGGER.error(ex); throw new InternalErrorRestEx(ex.getMessage()); } }
@Override public Response delete(String name, boolean cascade) throws ConflictRestEx, NotFoundRestEx, InternalErrorRestEx { try { long id = instanceAdminService.get(name).getId(); this.delete(id, cascade); return Response.status(Status.OK).entity("OK\n").build(); } catch (NotFoundServiceEx ex) { LOGGER.warn("GSInstance not found: " + name); throw new NotFoundRestEx("GSInstance not found: " + name); } catch (GeoFenceRestEx ex) { // already handled throw ex; } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }
@Override public void update(String name, RESTInputInstance instance) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { try { GSInstance old = instanceAdminService.get(name); update(old.getId(), instance); } catch (NotFoundServiceEx ex) { LOGGER.warn("GSInstance not found: " + name); throw new NotFoundRestEx("GSInstance not found: " + name); } }
/** * Gets the single instance of RulesManagerServiceImpl. * * @param instance the instance * @return single instance of RulesManagerServiceImpl */ private org.geoserver.geofence.core.model.GSInstance getInstance( GSInstanceModel instance) { org.geoserver.geofence.core.model.GSInstance remote_instance = null; try { if ((instance != null) && (instance.getId() != -1)) { remote_instance = geofenceRemoteService .getInstanceAdminService().get(instance.getId()); } } catch (Exception e) { logger.info(e.getMessage(), e); } return remote_instance; }
protected GSInstance getInstance(IdName filter) throws BadRequestRestEx, NotFoundRestEx { try { if ( filter.getId() != null ) { return instanceAdminService.get(filter.getId()); } else if ( filter.getName() != null ) { return instanceAdminService.get(filter.getName()); } else { throw new BadRequestRestEx("Bad GSInstance filter " + filter); } } catch (NotFoundServiceEx e) { LOGGER.warn("GSInstance not found " + filter); throw new NotFoundRestEx("GSInstance not found " + filter); } }
GSInstance instance = instances.get(name); if(instance == null) { instance = instanceAdminService.get(name); instances.put(name, instance);