Ejemplo n.º 1
0
  @GET
  public String retrieveAll(
      @DefaultValue("-1") @QueryParam("typeId") final int typeId,
      @DefaultValue("-1") @QueryParam("entityId") final int entityId,
      @Context final UriInfo uriInfo) {

    this.context.authenticatedUser().validateHasReadPermission(this.RESOURCE_NAME_FOR_PERMISSION);

    // FIXME - we dont use the ORM when doing fetches - we write SQL and fetch through JDBC
    // returning data to be serialized to JSON
    List<Template> templates = new ArrayList<Template>();

    if (typeId != -1 && entityId != -1) {
      templates =
          this.templateService.getAllByEntityAndType(
              TemplateEntity.values()[entityId], TemplateType.values()[typeId]);
    } else {
      templates = this.templateService.getAll();
    }

    final ApiRequestJsonSerializationSettings settings =
        this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    return this.toApiJsonSerializer.serialize(
        settings, templates, this.RESPONSE_TEMPLATES_DATA_PARAMETERS);
  }