Search in sources :

Example 1 with ElementSummaryJSON

use of io.hops.hopsworks.dela.old_dto.ElementSummaryJSON in project hopsworks by logicalclocks.

the class DelaService method getContentsForUser.

@GET
@Path("/transfers")
@Produces(MediaType.APPLICATION_JSON)
public Response getContentsForUser(@Context SecurityContext sc, @QueryParam("filter") TransfersFilter filter) throws DelaException {
    if (!filter.equals(TransfersFilter.USER)) {
        throw new DelaException(RESTCodes.DelaErrorCode.ILLEGAL_ARGUMENT, Level.FINE, DelaException.Source.LOCAL, "not handling filter value:" + filter);
    }
    Users user = jWTHelper.getUserPrincipal(sc);
    List<ProjectTeam> teams = projectCtrl.findProjectByUser(user.getEmail());
    List<Integer> projectIds = new LinkedList<>();
    for (ProjectTeam t : teams) {
        projectIds.add(t.getProject().getId());
    }
    HopsContentsSummaryJSON.Contents resp = delaTransferCtrl.getContents(projectIds);
    List<UserContentsSummaryJSON> userContents = new ArrayList<>();
    Iterator<Map.Entry<Integer, ElementSummaryJSON[]>> it = resp.getContents().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<Integer, ElementSummaryJSON[]> n = it.next();
        userContents.add(new UserContentsSummaryJSON(n.getKey(), n.getValue()));
    }
    GenericEntity<List<UserContentsSummaryJSON>> userContentsList = new GenericEntity<List<UserContentsSummaryJSON>>(userContents) {
    };
    return success(userContentsList);
}
Also used : ArrayList(java.util.ArrayList) Users(io.hops.hopsworks.persistence.entity.user.Users) DelaException(io.hops.hopsworks.exceptions.DelaException) LinkedList(java.util.LinkedList) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) GenericEntity(javax.ws.rs.core.GenericEntity) ElementSummaryJSON(io.hops.hopsworks.dela.old_dto.ElementSummaryJSON) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HopsContentsSummaryJSON(io.hops.hopsworks.dela.old_dto.HopsContentsSummaryJSON) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ElementSummaryJSON

use of io.hops.hopsworks.dela.old_dto.ElementSummaryJSON in project hopsworks by logicalclocks.

the class TransferDelaController method getContents.

/**
 * @return <upldDS, dwnlDS>
 */
public Pair<List<String>, List<String>> getContents() throws DelaException {
    if (!delaStateController.transferDelaAvailable()) {
        throw new DelaException(RESTCodes.DelaErrorCode.DELA_TRANSFER_NOT_AVAILABLE, Level.SEVERE, DelaException.Source.LOCAL);
    }
    HopsContentsSummaryJSON.Contents contents = TransferDelaController.this.getContents(new LinkedList<>());
    List<String> upldDSIds = new LinkedList<>();
    List<String> dwnlDSIds = new LinkedList<>();
    for (ElementSummaryJSON[] ea : contents.getContents().values()) {
        for (ElementSummaryJSON e : ea) {
            if (e.getTorrentStatus().toLowerCase().equals("uploading")) {
                upldDSIds.add(e.getTorrentId().getVal());
            } else if (e.getTorrentStatus().toLowerCase().equals("downloading")) {
                dwnlDSIds.add(e.getTorrentId().getVal());
            }
        }
    }
    return Pair.with(upldDSIds, dwnlDSIds);
}
Also used : ElementSummaryJSON(io.hops.hopsworks.dela.old_dto.ElementSummaryJSON) HopsContentsSummaryJSON(io.hops.hopsworks.dela.old_dto.HopsContentsSummaryJSON) DelaException(io.hops.hopsworks.exceptions.DelaException) LinkedList(java.util.LinkedList)

Aggregations

ElementSummaryJSON (io.hops.hopsworks.dela.old_dto.ElementSummaryJSON)2 HopsContentsSummaryJSON (io.hops.hopsworks.dela.old_dto.HopsContentsSummaryJSON)2 DelaException (io.hops.hopsworks.exceptions.DelaException)2 LinkedList (java.util.LinkedList)2 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)1 Users (io.hops.hopsworks.persistence.entity.user.Users)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 GenericEntity (javax.ws.rs.core.GenericEntity)1