Skip to content
Snippets Groups Projects
Commit 71d2497f authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

added create collection and part of delete

parent c6bcc836
No related branches found
No related tags found
No related merge requests found
......@@ -6,3 +6,4 @@
nbactions.xml
nb-configuration.xml
.env.development.local
/vospace-ui-frontend/nbproject/private/
......@@ -13,6 +13,7 @@ import it.inaf.ia2.vospace.ui.exception.VOSpaceStatusException;
import it.inaf.ia2.vospace.ui.exception.VOSpaceException;
import it.inaf.oats.vospace.datamodel.NodeUtils;
import static it.inaf.oats.vospace.datamodel.NodeUtils.urlEncodePath;
import it.inaf.oats.vospace.datamodel.collections.NodeCollection;
import it.inaf.oats.vospace.datamodel.collections.NodeCollectionsWrapper;
import java.io.IOException;
import java.io.InputStream;
......@@ -143,6 +144,31 @@ public class VOSpaceClient {
return protocols.get(0).getEndpoint();
}
public void createCollection(String name, Optional<String> token) {
NodeCollection nc = new NodeCollection();
nc.setTitle(name);
HttpRequest request = getRequest("/collections", token)
.header("Accept", useJson ? "application/json" : "text/xml")
.header("Content-Type", useJson ? "application/json" : "text/xml")
.PUT(HttpRequest.BodyPublishers.ofString(marshal(nc)))
.build();
call(request, BodyHandlers.ofInputStream(), 200, res -> null);
}
public void deleteCollection(Long id, Optional<String> token) {
HttpRequest request = getRequest("/collections?id="+id, token)
.header("Accept", useJson ? "application/json" : "text/xml")
.header("Content-Type", useJson ? "application/json" : "text/xml")
.DELETE()
.build();
call(request, BodyHandlers.ofInputStream(), 200, res -> null);
}
public Node createNode(Node node, Optional<String> token) {
String path = NodeUtils.getVosPath(node);
......
......@@ -11,11 +11,15 @@ import it.inaf.ia2.vospace.ui.client.VOSpaceClient;
import it.inaf.oats.vospace.datamodel.collections.NodeCollection;
import it.inaf.oats.vospace.datamodel.collections.NodeCollectionsWrapper;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
......@@ -41,4 +45,20 @@ public class NodeCollectionsController extends BaseController {
return ncw.getNodeCollections();
}
@PutMapping(value = "/collections", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createNodeCollection(User principal,
@RequestBody Map<String, Object> params)
throws Exception
{
String collectionName = (String) this.getRequiredParam(params, "collectionName");
LOG.debug("create new collection named {} for user {}",
collectionName, principal.getName());
// Call creation logic
client.createCollection(collectionName, tokenProvider.getToken());
return ResponseEntity.noContent().build();
}
}
file.reference.vospace-ui-frontend-public=public
files.encoding=UTF-8
site.root.folder=${file.reference.vospace-ui-frontend-public}
source.folder=
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.web.clientproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/clientside-project/1">
<name>vospace-ui-frontend</name>
</data>
</configuration>
</project>
This diff is collapsed.
......@@ -113,6 +113,31 @@ export default {
data: paths
});
},
createCollection(newCollectionName) {
let url = BASE_API_URL + 'collections';
return apiRequest({
method: 'PUT',
url: url,
withCredentials: true,
headers: {
'Cache-Control': 'no-cache'
},
data: {
collectionName: newCollectionName
}
});
},
deleteCollection(collectionId) {
let url = BASE_API_URL + 'collections?id='+collectionId;
return apiRequest({
method: 'DELETE',
url: url,
withCredentials: true,
headers: {
'Cache-Control': 'no-cache'
}
});
},
createFolder(path, newFolderName) {
let url = BASE_API_URL + 'folder';
return apiRequest({
......
......@@ -13,15 +13,16 @@
<div v-if="collections.length > 0" class="mb-3">
<table class="table b-table table-striped table-hover">
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="collection in collections" :key="collection.id">
<td>{{collection.id}}</td>
<td>{{collection.title}}</td>
<td></td>
</tr>
</tbody>
</table>
......
......@@ -248,6 +248,20 @@ export default new Vuex.Store({
});
commit('setCollectionsLoading', false);
},
createCollection({ dispatch }, newCollectionName) {
client.createCollection(newCollectionName)
.then(() => {
// Reload collections
dispatch('loadCollections');
});
},
deleteCollection({ dispatch }, collectionId) {
client.deleteCollection(collectionId)
.then(() => {
// Reload collections
dispatch('loadCollections');
});
},
loadUserInfo({ commit }) {
client.getUserInfo()
.then(res => commit('setUsername', res.username));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment