aboutsummaryrefslogtreecommitdiffstats
path: root/cos/cosmgr/src/main/java/com/cablelabs/vcpe/cos/cosmgr/CoSService.java
blob: e9390fc525717abd6c767ba71dd9a59a1f31161c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.cablelabs.vcpe.cos.cosmgr;

import com.cablelabs.vcpe.common.Dbg;
import com.cablelabs.vcpe.cos.cosbase.model.CoS;
import com.cablelabs.vcpe.cos.cosbase.repository.CoSRespositoryInMem;

import javax.ws.rs.*;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;

/**
 * Root resource (exposed at "myresource" path)
 */
@Path("cos")
public class CoSService
{

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public Response create(CoS cos)
  //--------------------------------------------------------
    {
        if ( cos == null) {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }

        Dbg.p("\nADDING [" + cos.getId() + "] to cos repo");
        CoSRespositoryInMem.INSTANCE.add(cos);
        CoSRespositoryInMem.INSTANCE.dump(0);
        return Response.ok().entity(cos).build();
    }

    @PUT
    @Path("{cosId}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public Response update(CoS cos)
  //--------------------------------------------------------
    {
        Dbg.p("\nUPDATING [" + cos.getId()+"]");
        CoSRespositoryInMem.INSTANCE.update(cos);
        CoSRespositoryInMem.INSTANCE.dump(0);
        return Response.ok().entity(cos).build();
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("{cosId}")
  //--------------------------------------------------------
    public Response get( @PathParam("cosId") String cosId )
  //--------------------------------------------------------
    {
        if ( cosId == null) {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
        Dbg.p("\nRETRIEVING ["+cosId+"]");
        CoSRespositoryInMem.INSTANCE.dump(1);
        CoS cos = CoSRespositoryInMem.INSTANCE.get(cosId);
        if (cos == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        cos.dump(1);
        return Response.ok().entity(cos).build();
    }

    @DELETE
    @Path("{cosId}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public Response delete(@PathParam("cosId") String cosId)
  //--------------------------------------------------------

    {
        if ( cosId == null) {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
        Dbg.p("\nDELETE:" + cosId);
        CoSRespositoryInMem.INSTANCE.delete(cosId);
        CoSRespositoryInMem.INSTANCE.dump(0);
        return Response.ok().build();
    }


    @GET
    @Path("list")
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public Response cosList()
  //--------------------------------------------------------
  // get a list of all CoS objects
    {
        Dbg.p("\nCOS GET ALL:");
        List cosList = CoSRespositoryInMem.INSTANCE.getAll();
        if (cosList == null  )
        {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        return Response.ok().entity(new GenericEntity<List<CoS>>(cosList) {}).build();
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
  //--------------------------------------------------------
    public CoS testGet()
  //--------------------------------------------------------
  // simple get to check out json format

    {
        CoS cos = new CoS();
        cos.setAllProps("testGetCoS", 100, 0.99, 17.43, 2.43, 0.01);
        return cos;
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
  //--------------------------------------------------------
    public String ping()
  //--------------------------------------------------------
  // simple ping to check connectivity
    {
        Dbg.p("In CoS Service simple get connection test server");
        return "... pingCos reponse";
    }
}