package net.explorviz.landscape.server.resources;

import java.util.List;
import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import net.explorviz.landscape.api.ExtensionApiImpl;
import net.explorviz.shared.landscape.model.store.Timestamp;

/**
 * REST resource providing {@link net.explorviz.landscape.model.store.Timestamp} data for the
 * frontend.
 */
@Path("v1/timestamps")
@RolesAllowed({"admin"})
public class TimestampResource {

  private final ExtensionApiImpl api;

  @Inject
  public TimestampResource(final ExtensionApiImpl api) {
    this.api = api;
  }

  /**
   * Returns an List of {@link net.explorviz.landscape.model.store.Timestamp} interval of
   * "intervalSize" after a specific passed "timestamp"
   *
   * @param afterTimestamp - a starting timestamp for the returned interval
   * @param intervalSize - the size of the interval
   * @return a filtered list of timestamps
   */
  @GET
  @Path("/subsequent-interval")
  @Produces("application/vnd.api+json")
  public List<Timestamp> getSubsequentTimestamps(@QueryParam("after") final long afterTimestamp,
      @QueryParam("intervalSize") final int intervalSize) {
    return this.api.getSubsequentTimestamps(afterTimestamp, intervalSize);
  }

  /**
   * Returns a List of all uploaded {@link net.explorviz.landscape.model.store.Timestamp}
   *
   * @return a list of all uploaded timestamps
   */
  @GET
  @Path("/all-uploaded")
  @Produces("application/vnd.api+json")
  public List<Timestamp> getUploadedTimestamps() {
    return this.api.getUploadedTimestamps();
  }

}

@@ -1726,11 +1726,2548 @@
 %0A  %7D%0D%0A%0D%0A
+%0D%0A  /**%0D%0A   * Retrieves timestamps AFTER a passed%0D%0A   * %7B@link net.explorviz.shared.landscape.model.store.Timestamp%7D.%0D%0A   *%0D%0A   * @param allTimestamps - All timestamps within the system%0D%0A   * @param afterTimestamp - Define the timestamp which sets the limit%0D%0A   * @param intervalSize - The number of retrieved timestamps%0D%0A   * @return List of Timestamp%0D%0A   */%0D%0A  private List%3CTimestamp%3E filterTimestampsAfterTimestamp(final List%3CTimestamp%3E allTimestamps,%0D%0A      final long afterTimestamp, final int intervalSize) %7B%0D%0A%0D%0A    final int timestampListSize = allTimestamps.size();%0D%0A%0D%0A    // search the passed timestamp%0D%0A    final Timestamp foundTimestamp = getTimestampPosition(allTimestamps, afterTimestamp);%0D%0A    final int foundTimestampPosition = allTimestamps.indexOf(foundTimestamp);%0D%0A%0D%0A    // no timestamp was found%0D%0A    if (foundTimestampPosition == -1) %7B%0D%0A      return new LinkedList%3C%3E();%0D%0A    %7D else %7B%0D%0A      try %7B%0D%0A        if (intervalSize == 0 %7C%7C intervalSize %3E timestampListSize) %7B%0D%0A          // all timestamps starting at position%0D%0A          return allTimestamps.subList(foundTimestampPosition, timestampListSize);%0D%0A        %7D else %7B%0D%0A          if (foundTimestampPosition + intervalSize %3E timestampListSize) %7B%0D%0A            return allTimestamps.subList(foundTimestampPosition, timestampListSize);%0D%0A          %7D else %7B%0D%0A            return allTimestamps.subList(foundTimestampPosition,%0D%0A                foundTimestampPosition + intervalSize);%0D%0A          %7D%0D%0A        %7D%0D%0A      %7D catch (final IllegalArgumentException e) %7B%0D%0A        throw new WebApplicationException(e);%0D%0A      %7D%0D%0A    %7D%0D%0A  %7D%0D%0A%0D%0A  /**%0D%0A   * Retrieves the a passed %7B@link Timestamp%7D within a list of timestamps if found, otherwise the%0D%0A   * following timestamp.%0D%0A   *%0D%0A   * @param timestamps - a list of timestamps%0D%0A   * @param searchedTimestamp - a specific timestamp to be found%0D%0A   * @return a retrieved timestamp%0D%0A   */%0D%0A  private static Timestamp getTimestampPosition(final List%3CTimestamp%3E timestamps,%0D%0A      final long searchedTimestamp) %7B%0D%0A%0D%0A    final Iterator%3CTimestamp%3E iterator = timestamps.iterator();%0D%0A%0D%0A    while (iterator.hasNext()) %7B%0D%0A%0D%0A      final Timestamp currentTimestamp = iterator.next();%0D%0A%0D%0A      // searched timestamp found%0D%0A      if (currentTimestamp.getTimestamp() == searchedTimestamp) %7B%0D%0A        return currentTimestamp;%0D%0A      %7D%0D%0A      // next timestamp later than searched timestamp found%0D%0A      else if (currentTimestamp.getTimestamp() %3E searchedTimestamp) %7B%0D%0A        return currentTimestamp;%0D%0A      %7D%0D%0A    %7D%0D%0A    return new Timestamp();%0D%0A  %7D%0D%0A%0D%0A
 %7D%0D%0A

Move subsequent timestamp calculation from shared to resource