Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cyclops/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,24 @@ func (server *ModCyclopsServer) handleUpdateProject(w http.ResponseWriter, req *
return nil
}

func (server *ModCyclopsServer) handleShowSetsInProject(w http.ResponseWriter, req *http.Request, caption string) error {
projectId := chi.URLParam(req, "projectId")
command := "show sets in project " + projectId + ";"
server.Log("command", command)
resp, err := server.sendToCCMS(caption+" "+projectId, command)
if err != nil {
return fmt.Errorf("could not fetch show-sets response: %w", err)
}

result := readResults(resp)[0]
sets := make([]any, 0)
for val := range result.Data() {
sets = append(sets, val.Values()[0])
}
setList := SetList{Sets: sets}
return server.respondWithJSON(w, setList, caption)
}

// -----------------------------------------------------------------------------

type FundList struct {
Expand Down
23 changes: 23 additions & 0 deletions cyclops/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,29 @@ func TestHandleShowSets(t *testing.T) {
}
}

func TestHandleShowSetsInProject(t *testing.T) {
fake := &fakeCCMS{resp: listResponse("mike.object", "mike.endangered")}
server := newTestServer(fake)

rr := httptest.NewRecorder()
err := server.handleShowSetsInProject(rr, jsonRequest("", map[string]string{"projectId": "mike"}), "show sets in project")
if err != nil {
t.Fatalf("handleShowSets returned error: %v", err)
}

assertEqual(t, "command sent to CCMS", fake.lastCmd, "show sets in project mike;")

var got SetList
err = json.Unmarshal(rr.Body.Bytes(), &got)
if err != nil {
t.Fatalf("could not decode response body %q: %v", rr.Body.String(), err)
}
want := SetList{Sets: []any{"mike.object", "mike.endangered"}}
if !reflect.DeepEqual(got, want) {
t.Errorf("translated response:\n got %+v\nwant %+v", got, want)
}
}

func TestHandleShowFunds(t *testing.T) {
fake := &fakeCCMS{resp: listResponse("general", "endowment")}
server := newTestServer(fake)
Expand Down
3 changes: 3 additions & 0 deletions cyclops/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func MakeModCyclopsServer(logger *catlogger.Logger, ccmsClient CCMSClient, root
r.Put("/cyclops/projects/{projectId}", func(w http.ResponseWriter, req *http.Request) {
server.runWithErrorHandling(w, req, server.handleUpdateProject, "update project")
})
r.Get("/cyclops/projects/{projectId}/sets", func(w http.ResponseWriter, req *http.Request) {
server.runWithErrorHandling(w, req, server.handleShowSetsInProject, "show sets in project")
})
r.Get("/cyclops/funds", func(w http.ResponseWriter, req *http.Request) {
server.runWithErrorHandling(w, req, server.handleShowFunds, "show funds")
})
Expand Down
9 changes: 9 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@
"cyclops.projects.put"
]
},
{
"methods": [
"GET"
],
"pathPattern": "/cyclops/projects/{id}/sets",
"permissionsRequired": [
"cyclops.sets.read"
]
},
{
"methods": [
"GET"
Expand Down
21 changes: 11 additions & 10 deletions htdocs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<script src="sendRequest.js" defer></script>
<script>
function addRecord() {
postData('/cyclops/sets/test.mike/add', { from: 'reserve', cond: `author = 'Adams, John'` })
postData('/cyclops/sets/korea_lit.mike/add', { from: 'reserve', cond: `author = 'Adams, John'` })
}
</script>
</head>
Expand Down Expand Up @@ -66,18 +66,19 @@
origins: [{ id: 'lehigh', name: 'LeHigh' }, { id: 'nyu', name: 'New York U.' }],
destinations: [{ id: 'clockss', name: 'CLOCKSS' }],
})">modify project "literature of North Korea"</button></li>
<li><a href="/cyclops/projects/korea_lit/sets">list of sets in project "literature of North Korea"</a></li>
</ul>
<ul>
<li><a href="/cyclops/sets">list of sets</a></li>
<li><button class="link-button" onclick="postData('/cyclops/sets', { name: 'test.mike' })">create set "test.mike"</button></li>
<li><button class="link-button" onclick="deleteObject('/cyclops/sets/test.mike')">delete set "test.mike"</button></li>
<li><a href="/cyclops/sets/test.mike?fields=%2A&cond=143100000%20%3C%3D%20age%20AND%20age%20%3C%3D%20201400000&filter=jurassic&tag=dino,ptero&sort=author,title&offset=20&limit=10">retrieve from set "test.mike"</a></li>
<li><a href="/cyclops/sets/test.mike?fields=%2A&cond=title='rings' or author='lewis'&sort=author&offset=20&limit=10">retrieve from set "test.mike" using only supported params</a></li>
<li><a href="/cyclops/sets/test.mike?fields=%2A">retrieve everything from set "test.mike"</a></li>
<li><button class="link-button" onclick="postData('/cyclops/sets/test.mike/add', { from: 'reserve', cond: `author = 'Adams, John'` })">add objects to set "test.mike"</button></li>
<li><button class="link-button" onclick="postData('/cyclops/sets/test.mike/remove', { cond: 'id = 55017' })">remove item 55017 from set "test.mike"</button></li>
<li><button class="link-button" onclick="postData('/cyclops/sets/test.mike/tag/dino', { op: 'add', cond: 'title LIKE %saur', filter: 'jurassic' })">add tag "dino" to records in set "test.mike"</button></li>
<li><button class="link-button" onclick="postData('/cyclops/sets/test.mike/tag/dino', { op: 'remove', cond: 'author LIKE %taylor%', filter: 'cretaceous' })">remove tag "dino" from records in set "test.mike"</button></li>
<li><button class="link-button" onclick="postData('/cyclops/sets', { name: 'korea_lit.mike' })">create set "korea_lit.mike"</button></li>
<li><button class="link-button" onclick="deleteObject('/cyclops/sets/korea_lit.mike')">delete set "korea_lit.mike"</button></li>
<li><a href="/cyclops/sets/korea_lit.mike?fields=%2A&cond=143100000%20%3C%3D%20age%20AND%20age%20%3C%3D%20201400000&filter=jurassic&tag=dino,ptero&sort=author,title&offset=20&limit=10">retrieve from set "korea_lit.mike"</a></li>
<li><a href="/cyclops/sets/korea_lit.mike?fields=%2A&cond=title='rings' or author='lewis'&sort=author&offset=20&limit=10">retrieve from set "korea_lit.mike" using only supported params</a></li>
<li><a href="/cyclops/sets/korea_lit.mike?fields=%2A">retrieve everything from set "korea_lit.mike"</a></li>
<li><button class="link-button" onclick="postData('/cyclops/sets/korea_lit.mike/add', { from: 'reserve', cond: `author = 'Adams, John'` })">add objects to set "korea_lit.mike"</button></li>
<li><button class="link-button" onclick="postData('/cyclops/sets/korea_lit.mike/remove', { cond: 'id = 55017' })">remove item 55017 from set "korea_lit.mike"</button></li>
<li><button class="link-button" onclick="postData('/cyclops/sets/korea_lit.mike/tag/dino', { op: 'add', cond: 'title LIKE %saur', filter: 'jurassic' })">add tag "dino" to records in set "korea_lit.mike"</button></li>
<li><button class="link-button" onclick="postData('/cyclops/sets/korea_lit.mike/tag/dino', { op: 'remove', cond: 'author LIKE %taylor%', filter: 'cretaceous' })">remove tag "dino" from records in set "korea_lit.mike"</button></li>
</ul>
See also:
<a href="form.html">the interactive form</a>
Expand Down
10 changes: 10 additions & 0 deletions ramls/cyclops.raml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ documentation:
responses:
204:
description: No content is returned.
/sets:
description: "Sets of objects (books, films, etc.) in this project"
get:
description: "Return a list of the names of all known sets in this project"
responses:
200:
body:
application/json:
type: !include sets-schema.json
example: !include examples/show-sets-example.json
/funds:
description: "Funds that can be associated with a project or assigned to a spectre"
get:
Expand Down