Skip to content
Snippets Groups Projects
Commit e5a885af authored by Art Lowel's avatar Art Lowel
Browse files

Add support for Communities

parent 45d174cc
No related branches found
No related tags found
No related merge requests found
import { autoserialize, inheritSerialization, autoserializeAs } from "cerialize";
import { NormalizedDSpaceObject } from "./normalized-dspace-object.model";
import { Community } from "../../shared/community.model";
import { mapsTo, relationship } from "../builders/build-decorators";
import { NormalizedDSOType } from "./normalized-dspace-object-type";
@mapsTo(Community)
@inheritSerialization(NormalizedDSpaceObject)
export class NormalizedCommunity extends NormalizedDSpaceObject {
/**
* A string representing the unique handle of this Community
*/
@autoserialize
handle: string;
/**
* The Bitstream that represents the logo of this Community
*/
logo: string;
/**
* An array of Communities that are direct parents of this Community
*/
parents: Array<string>;
/**
* The Community that owns this Community
*/
owner: string;
@autoserialize
@relationship(NormalizedDSOType.NormalizedCollection)
collections: Array<string>;
}
......@@ -5,25 +5,29 @@ import { NormalizedItem } from "./normalized-item.model";
import { NormalizedCollection } from "./normalized-collection.model";
import { GenericConstructor } from "../../shared/generic-constructor";
import { NormalizedDSOType } from "./normalized-dspace-object-type";
import { NormalizedCommunity } from "./normalized-community.model";
export class NormalizedDSOFactory {
public static getConstructor(type: NormalizedDSOType): GenericConstructor<NormalizedDSpaceObject> {
switch (type) {
switch (type) {
case NormalizedDSOType.NormalizedBitstream: {
return NormalizedBitstream
}
}
case NormalizedDSOType.NormalizedBundle: {
return NormalizedBundle
}
}
case NormalizedDSOType.NormalizedItem: {
return NormalizedItem
}
}
case NormalizedDSOType.NormalizedCollection: {
return NormalizedCollection
}
default: {
return undefined;
}
}
case NormalizedDSOType.NormalizedCommunity: {
return NormalizedCommunity
}
default: {
return undefined;
}
}
}
}
......@@ -2,5 +2,6 @@ export enum NormalizedDSOType {
NormalizedBitstream,
NormalizedBundle,
NormalizedItem,
NormalizedCollection
NormalizedCollection,
NormalizedCommunity
}
......@@ -10,6 +10,7 @@ import { CollectionDataService } from "./data/collection-data.service";
import { ItemDataService } from "./data/item-data.service";
import { RequestService } from "./data/request.service";
import { RemoteDataBuildService } from "./cache/builders/remote-data-build.service";
import { CommunityDataService } from "./data/community-data.service";
const IMPORTS = [
CommonModule,
......@@ -25,6 +26,7 @@ const EXPORTS = [
];
const PROVIDERS = [
CommunityDataService,
CollectionDataService,
ItemDataService,
DSpaceRESTv2Service,
......
import { Injectable } from "@angular/core";
import { DataService } from "./data.service";
import { Community } from "../shared/community.model";
import { ObjectCacheService } from "../cache/object-cache.service";
import { ResponseCacheService } from "../cache/response-cache.service";
import { Store } from "@ngrx/store";
import { NormalizedCommunity } from "../cache/models/normalized-community.model";
import { CoreState } from "../core.reducers";
import { RequestService } from "./request.service";
import { RemoteDataBuildService } from "../cache/builders/remote-data-build.service";
@Injectable()
export class CommunityDataService extends DataService<NormalizedCommunity, Community> {
protected endpoint = '/communities';
constructor(
protected objectCache: ObjectCacheService,
protected responseCache: ResponseCacheService,
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected store: Store<CoreState>
) {
super(NormalizedCommunity);
}
}
import { DSpaceObject } from "./dspace-object.model";
import { Bitstream } from "./bitstream.model";
import { Collection } from "./collection.model";
import { RemoteData } from "../data/remote-data";
export class Community extends DSpaceObject {
/**
* A string representing the unique handle of this Community
*/
handle: string;
/**
* The introductory text of this Community
* Corresponds to the metadata field dc.description
*/
get introductoryText(): string {
return this.findMetadata("dc.description");
}
/**
* The short description: HTML
* Corresponds to the metadata field dc.description.abstract
*/
get shortDescription(): string {
return this.findMetadata("dc.description.abstract");
}
/**
* The copyright text of this Community
* Corresponds to the metadata field dc.rights
*/
get copyrightText(): string {
return this.findMetadata("dc.rights");
}
/**
* The sidebar text of this Community
* Corresponds to the metadata field dc.description.tableofcontents
*/
get sidebarText(): string {
return this.findMetadata("dc.description.tableofcontents");
}
/**
* The Bitstream that represents the logo of this Community
*/
logo: RemoteData<Bitstream>;
/**
* An array of Communities that are direct parents of this Community
*/
parents: Array<Community>;
/**
* The Community that owns this Community
*/
owner: Community;
collections: Array<RemoteData<Collection>>;
}
import { COMMUNITIES } from "./communities";
const util = require('util');
const { Router } = require('express');
......@@ -51,6 +52,67 @@ export function createMockApi() {
let router = Router();
router.route('/communities')
.get(function(req, res) {
console.log('GET');
// 70ms latency
setTimeout(function() {
res.json(toHALResponse(req, COMMUNITIES));
}, 0);
// })
// .post(function(req, res) {
// console.log('POST', util.inspect(req.body, { colors: true }));
// let community = req.body;
// if (community) {
// COMMUNITIES.push({
// value: community.value,
// created_at: new Date(),
// completed: community.completed,
// id: COMMUNITY_COUNT++
// });
// return res.json(community);
// }
//
// return res.end();
});
router.param('community_id', function(req, res, next, community_id) {
// ensure correct prop type
let id = req.params.community_id;
try {
req.community_id = id;
req.community = COMMUNITIES.find((community) => {
return community.id === id;
});
next();
} catch (e) {
next(new Error('failed to load community'));
}
});
router.route('/communities/:community_id')
.get(function(req, res) {
// console.log('GET', util.inspect(req.community.id, { colors: true }));
res.json(toHALResponse(req, req.community));
// })
// .put(function(req, res) {
// console.log('PUT', util.inspect(req.body, { colors: true }));
//
// let index = COMMUNITIES.indexOf(req.community);
// let community = COMMUNITIES[index] = req.body;
//
// res.json(community);
// })
// .delete(function(req, res) {
// console.log('DELETE', req.community_id);
//
// let index = COMMUNITIES.indexOf(req.community);
// COMMUNITIES.splice(index, 1);
//
// res.json(req.community);
});
router.route('/collections')
.get(function(req, res) {
console.log('GET');
......
export const COMMUNITIES = [
{
"name": "Community 1",
"handle": "10673/1",
"id": "6631",
"uuid": "83cd3281-f241-48be-9234-d876f8010d14",
"type": "community",
"metadata": [
{
"key": "dc.description",
"value": "<p>This is the introductory text for the <em>Sample Community</em> on the DSpace Demonstration Site. It is editable by System or Community Administrators (of this Community).</p>\r\n<p><strong>DSpace Communities may contain one or more Sub-Communities or Collections (of Items).</strong></p>\r\n<p>This particular Community has its own logo (the <a href=\"http://www.duraspace.org/\">DuraSpace</a> logo).</p>",
"language": null
},
{
"key": "dc.description.abstract",
"value": "This is a sample top-level community",
"language": null
},
{
"key": "dc.description.tableofcontents",
"value": "<p>This is the <em>news section</em> for this <em>Sample Community</em>. System or Community Administrators (of this Community) can edit this News field.</p>",
"language": null
},
{
"key": "dc.rights",
"value": "<p><em>If this Community had special copyright text to display, it would be displayed here.</em></p>",
"language": null
},
{
"key": "dc.title",
"value": "Sample Community",
"language": null
}
],
"_links": {
"self": {
"href": "http://dspace7.4science.it/dspace-spring-rest/api/core/community/9076bd16-e69a-48d6-9e41-0238cb40d863"
},
"collections": [
{ "href": "/collections/5179" }
]
}
},
{
"name": "Community 2",
"handle": "10673/2",
"id": "2365",
"uuid": "80eec4c6-70bd-4beb-b3d4-5d46c6343157",
"type": "community",
"metadata": [
{
"key": "dc.description",
"value": "<p>This is the introductory text for the <em>Sample Community</em> on the DSpace Demonstration Site. It is editable by System or Community Administrators (of this Community).</p>\r\n<p><strong>DSpace Communities may contain one or more Sub-Communities or Collections (of Items).</strong></p>\r\n<p>This particular Community has its own logo (the <a href=\"http://www.duraspace.org/\">DuraSpace</a> logo).</p>",
"language": null
},
{
"key": "dc.description.abstract",
"value": "This is a sample top-level community",
"language": null
},
{
"key": "dc.description.tableofcontents",
"value": "<p>This is the <em>news section</em> for this <em>Sample Community</em>. System or Community Administrators (of this Community) can edit this News field.</p>",
"language": null
},
{
"key": "dc.rights",
"value": "<p><em>If this Community had special copyright text to display, it would be displayed here.</em></p>",
"language": null
},
{
"key": "dc.title",
"value": "Sample Community",
"language": null
}
],
"_links": {
"self": {
"href": "http://dspace7.4science.it/dspace-spring-rest/api/core/community/9076bd16-e69a-48d6-9e41-0238cb40d863"
},
"collections": [
{ "href": "/collections/6547" }
]
}
}
];
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment