/** * @param writer */ private void writeSystemScopes(JsonWriter writer) { for (SystemScope sysScope : sysScopeRepository.getAll()) { try { writer.beginObject(); writer.name(ID).value(sysScope.getId()); writer.name(DESCRIPTION).value(sysScope.getDescription()); writer.name(ICON).value(sysScope.getIcon()); writer.name(VALUE).value(sysScope.getValue()); writer.name(RESTRICTED).value(sysScope.isRestricted()); writer.name(DEFAULT_SCOPE).value(sysScope.isDefaultScope()); writer.endObject(); logger.debug("Wrote system scope {}", sysScope.getId()); } catch (IOException ex) { logger.error("Unable to write system scope {}", sysScope.getId(), ex); } } logger.info("Done writing system scopes"); }
reader.beginArray(); while (reader.hasNext()) { SystemScope scope = new SystemScope(); reader.beginObject(); while (reader.hasNext()) { reader.skipValue(); } else if (name.equals(VALUE)) { scope.setValue(reader.nextString()); } else if (name.equals(DESCRIPTION)) { scope.setDescription(reader.nextString()); } else if (name.equals(RESTRICTED)) { scope.setRestricted(reader.nextBoolean()); } else if (name.equals(DEFAULT_SCOPE)) { scope.setDefaultScope(reader.nextBoolean()); } else if (name.equals(ICON)) { scope.setIcon(reader.nextString()); } else { logger.debug("found unexpected entry");
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public String createScope(@RequestBody String json, ModelMap m) { SystemScope scope = gson.fromJson(json, SystemScope.class); SystemScope alreadyExists = scopeService.getByValue(scope.getValue()); if (alreadyExists != null) { //Error, cannot save a scope with the same value as an existing one logger.error("Error: attempting to save a scope with a value that already exists: " + scope.getValue()); m.put(HttpCodeView.CODE, HttpStatus.CONFLICT); m.put(JsonErrorView.ERROR_MESSAGE, "A scope with value " + scope.getValue() + " already exists, please choose a different value."); return JsonErrorView.VIEWNAME; } scope = scopeService.save(scope); if (scope != null && scope.getId() != null) { m.put(JsonEntityView.ENTITY, scope); return JsonEntityView.VIEWNAME; } else { logger.error("createScope failed; JSON was invalid: " + json); m.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.put(JsonErrorView.ERROR_MESSAGE, "Could not save new scope " + scope + ". The scope service failed to return a saved entity."); return JsonErrorView.VIEWNAME; } }
@Override @Transactional(value="defaultTransactionManager") public void remove(SystemScope scope) { SystemScope found = getById(scope.getId()); if (found != null) { em.remove(found); } }
@Override public String apply(SystemScope input) { if (input == null) { return null; } else { return input.getValue(); } } };
@Override public boolean apply(SystemScope input) { return (input != null && input.isDefaultScope()); } };
@Override public boolean apply(SystemScope input) { return (input != null && input.isRestricted()); } };
@Override public SystemScope apply(String input) { if (Strings.isNullOrEmpty(input)) { return null; } else { // get the real scope if it's available SystemScope s = getByValue(input); if (s == null) { // make a fake one otherwise s = new SystemScope(input); } return s; } } };
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public String createScope(@RequestBody String json, ModelMap m) { SystemScope scope = gson.fromJson(json, SystemScope.class); SystemScope alreadyExists = scopeService.getByValue(scope.getValue()); if (alreadyExists != null) { //Error, cannot save a scope with the same value as an existing one logger.error("Error: attempting to save a scope with a value that already exists: " + scope.getValue()); m.put(HttpCodeView.CODE, HttpStatus.CONFLICT); m.put(JsonErrorView.ERROR_MESSAGE, "A scope with value " + scope.getValue() + " already exists, please choose a different value."); return JsonErrorView.VIEWNAME; } scope = scopeService.save(scope); if (scope != null && scope.getId() != null) { m.put(JsonEntityView.ENTITY, scope); return JsonEntityView.VIEWNAME; } else { logger.error("createScope failed; JSON was invalid: " + json); m.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.put(JsonErrorView.ERROR_MESSAGE, "Could not save new scope " + scope + ". The scope service failed to return a saved entity."); return JsonErrorView.VIEWNAME; } }
@Override @Transactional(value="defaultTransactionManager") public SystemScope save(SystemScope scope) { return saveOrUpdate(scope.getId(), em, scope); }
@Override public boolean apply(SystemScope input) { return (input != null && input.isDefaultScope()); } };
@Override public boolean apply(SystemScope input) { return (input != null && input.isRestricted()); } };
@Override public SystemScope apply(String input) { if (Strings.isNullOrEmpty(input)) { return null; } else { // get the real scope if it's available SystemScope s = getByValue(input); if (s == null) { // make a fake one otherwise s = new SystemScope(input); } return s; } } };
reader.beginArray(); while (reader.hasNext()) { SystemScope scope = new SystemScope(); reader.beginObject(); while (reader.hasNext()) { reader.skipValue(); } else if (name.equals("value")) { scope.setValue(reader.nextString()); } else if (name.equals("description")) { scope.setDescription(reader.nextString()); } else if (name.equals("allowDynReg")) { scope.setRestricted(!reader.nextBoolean()); } else if (name.equals("defaultScope")) { scope.setDefaultScope(reader.nextBoolean()); } else if (name.equals("icon")) { scope.setIcon(reader.nextString()); } else { logger.debug("found unexpected entry");
/** * @param writer */ private void writeSystemScopes(JsonWriter writer) { for (SystemScope sysScope : sysScopeRepository.getAll()) { try { writer.beginObject(); writer.name(ID).value(sysScope.getId()); writer.name(DESCRIPTION).value(sysScope.getDescription()); writer.name(ICON).value(sysScope.getIcon()); writer.name(VALUE).value(sysScope.getValue()); writer.name(RESTRICTED).value(sysScope.isRestricted()); writer.name(DEFAULT_SCOPE).value(sysScope.isDefaultScope()); writer.endObject(); logger.debug("Wrote system scope {}", sysScope.getId()); } catch (IOException ex) { logger.error("Unable to write system scope {}", sysScope.getId(), ex); } } logger.info("Done writing system scopes"); }
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public String updateScope(@PathVariable("id") Long id, @RequestBody String json, ModelMap m) { SystemScope existing = scopeService.getById(id); SystemScope scope = gson.fromJson(json, SystemScope.class); if (existing != null && scope != null) { if (existing.getId().equals(scope.getId())) { // sanity check scope = scopeService.save(scope); m.put(JsonEntityView.ENTITY, scope); return JsonEntityView.VIEWNAME; } else { logger.error("updateScope failed; scope ids to not match: got " + existing.getId() + " and " + scope.getId()); m.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.put(JsonErrorView.ERROR_MESSAGE, "Could not update scope. Scope ids to not match: got " + existing.getId() + " and " + scope.getId()); return JsonErrorView.VIEWNAME; } } else { logger.error("updateScope failed; scope with id " + id + " not found."); m.put(HttpCodeView.CODE, HttpStatus.NOT_FOUND); m.put(JsonErrorView.ERROR_MESSAGE, "Could not update scope. The scope with id " + id + " could not be found."); return JsonErrorView.VIEWNAME; } }
@Override public String apply(SystemScope input) { if (input == null) { return null; } else { return input.getValue(); } } };
reader.beginArray(); while (reader.hasNext()) { SystemScope scope = new SystemScope(); reader.beginObject(); while (reader.hasNext()) { reader.skipValue(); } else if (name.equals(VALUE)) { scope.setValue(reader.nextString()); } else if (name.equals(DESCRIPTION)) { scope.setDescription(reader.nextString()); } else if (name.equals(RESTRICTED)) { scope.setRestricted(reader.nextBoolean()); } else if (name.equals(DEFAULT_SCOPE)) { scope.setDefaultScope(reader.nextBoolean()); } else if (name.equals(ICON)) { scope.setIcon(reader.nextString()); } else if (name.equals(STRUCTURED)) { logger.warn("Found a structured scope, ignoring structure");
@Override public SystemScope getById(final Long aLong) { for (final SystemScope scope : scopes) { if (scope.getId().equals(aLong)) { return scope; } } return null; }