use of org.dspace.content.Community in project DSpace by DSpace.
the class ItemIndexFactoryImpl method getLocations.
@Override
public List<String> getLocations(Context context, IndexableItem indexableDSpaceObject) throws SQLException {
final Item item = indexableDSpaceObject.getIndexedObject();
List<String> locations = new ArrayList<>();
// build list of community ids
List<Community> communities = itemService.getCommunities(context, item);
// build list of collection ids
List<Collection> collections = item.getCollections();
// now put those into strings
int i = 0;
for (i = 0; i < communities.size(); i++) {
locations.add("m" + communities.get(i).getID());
}
for (i = 0; i < collections.size(); i++) {
locations.add("l" + collections.get(i).getID());
}
return locations;
}
use of org.dspace.content.Community in project DSpace by DSpace.
the class CitationDocumentServiceImpl method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
// Add valid format MIME types to set. This could be put in the Schema
// instead.
// Populate RASTER_MIMES
SVG_MIMES.add("image/jpeg");
SVG_MIMES.add("image/pjpeg");
SVG_MIMES.add("image/png");
SVG_MIMES.add("image/gif");
// Populate SVG_MIMES
SVG_MIMES.add("image/svg");
SVG_MIMES.add("image/svg+xml");
// Populate PDF_MIMES
PDF_MIMES.add("application/pdf");
PDF_MIMES.add("application/x-pdf");
// Populate VALID_TYPES
VALID_TYPES.addAll(PDF_MIMES);
// Global enabled?
citationEnabledGlobally = configurationService.getBooleanProperty("citation-page.enable_globally", false);
// Load enabled collections
String[] citationEnabledCollections = configurationService.getArrayProperty("citation-page.enabled_collections");
citationEnabledCollectionsList = Arrays.asList(citationEnabledCollections);
// Load enabled communities, and add to collection-list
String[] citationEnabledCommunities = configurationService.getArrayProperty("citation-page.enabled_communities");
if (citationEnabledCollectionsList == null) {
citationEnabledCollectionsList = new ArrayList<>();
}
if (citationEnabledCommunities != null && citationEnabledCommunities.length > 0) {
Context context = null;
try {
context = new Context();
for (String communityString : citationEnabledCommunities) {
DSpaceObject dsoCommunity = handleService.resolveToObject(context, communityString.trim());
if (dsoCommunity instanceof Community) {
Community community = (Community) dsoCommunity;
List<Collection> collections = communityService.getAllCollections(context, community);
for (Collection collection : collections) {
citationEnabledCollectionsList.add(collection.getHandle());
}
} else {
log.error("Invalid community for citation.enabled_communities, value:" + communityString.trim());
}
}
} catch (SQLException e) {
log.error(e.getMessage());
} finally {
if (context != null) {
context.abort();
}
}
}
// Configurable text/fields, we'll set sane defaults
header1 = configurationService.getArrayProperty("citation-page.header1");
if (header1 == null || header1.length == 0) {
header1 = new String[] { "DSpace Institution", "" };
}
header2 = configurationService.getArrayProperty("citation-page.header2");
if (header2 == null || header2.length == 0) {
header2 = new String[] { "DSpace Repository", "http://dspace.org" };
}
fields = configurationService.getArrayProperty("citation-page.fields");
if (fields == null || fields.length == 0) {
fields = new String[] { "dc.date.issued", "dc.title", "dc.creator", "dc.contributor.author", "dc.publisher", "_line_", "dc.identifier.citation", "dc.identifier.uri" };
}
String footerConfig = configurationService.getProperty("citation-page.footer");
if (StringUtils.isNotBlank(footerConfig)) {
footer = footerConfig;
} else {
footer = "Downloaded from DSpace Repository, DSpace Institution's institutional repository";
}
String pageformatCfg = configurationService.getProperty("citation-page.page_format");
if (pageformatCfg != null) {
if (pageformatCfg.equalsIgnoreCase("A4")) {
citationPageFormat = PDRectangle.A4;
} else if (!pageformatCfg.equalsIgnoreCase("LETTER")) {
log.info("Citation-page: Unknown page format ' " + pageformatCfg + "', using LETTER.");
}
}
// Ensure a temp directory is available
String tempDirString = configurationService.getProperty("dspace.dir") + File.separator + "temp";
tempDir = new File(tempDirString);
if (!tempDir.exists()) {
boolean success = tempDir.mkdir();
if (success) {
log.info("Created temp directory at: " + tempDirString);
} else {
log.info("Unable to create temp directory at: " + tempDirString);
}
}
}
use of org.dspace.content.Community in project DSpace by DSpace.
the class CollectionIndexFactoryImpl method getCollectionLocations.
@Override
public List<String> getCollectionLocations(Context context, Collection collection) throws SQLException {
List<String> locations = new ArrayList<>();
// build list of community ids
List<Community> communities = ContentServiceFactory.getInstance().getCommunityService().getAllParents(context, collection);
// now put those into strings
for (Community community : communities) {
locations.add("m" + community.getID());
}
return locations;
}
use of org.dspace.content.Community in project DSpace by DSpace.
the class SolrServiceResourceRestrictionPlugin method additionalIndex.
@Override
public void additionalIndex(Context context, IndexableObject idxObj, SolrInputDocument document) {
DSpaceObject dso = null;
if (idxObj instanceof IndexableDSpaceObject) {
dso = ((IndexableDSpaceObject) idxObj).getIndexedObject();
} else if (idxObj instanceof IndexableInProgressSubmission) {
final InProgressSubmission inProgressSubmission = ((IndexableInProgressSubmission) idxObj).getIndexedObject();
dso = inProgressSubmission.getItem();
} else if (idxObj instanceof IndexablePoolTask) {
final PoolTask poolTask = ((IndexablePoolTask) idxObj).getIndexedObject();
dso = poolTask.getWorkflowItem().getItem();
} else if (idxObj instanceof IndexableClaimedTask) {
final ClaimedTask claimedTask = ((IndexableClaimedTask) idxObj).getIndexedObject();
dso = claimedTask.getWorkflowItem().getItem();
}
if (dso != null) {
try {
List<ResourcePolicy> policies = authorizeService.getPoliciesActionFilter(context, dso, Constants.READ);
for (ResourcePolicy resourcePolicy : policies) {
if (resourcePolicyService.isDateValid(resourcePolicy)) {
String fieldValue;
if (resourcePolicy.getGroup() != null) {
// We have a group add it to the value
fieldValue = "g" + resourcePolicy.getGroup().getID();
} else {
// We have an eperson add it to the value
fieldValue = "e" + resourcePolicy.getEPerson().getID();
}
document.addField("read", fieldValue);
}
// remove the policy from the cache to save memory
context.uncacheEntity(resourcePolicy);
}
// going up through the hierarchy for communities, collections and items
while (dso != null) {
if (dso instanceof Community || dso instanceof Collection || dso instanceof Item) {
List<ResourcePolicy> policiesAdmin = authorizeService.getPoliciesActionFilter(context, dso, Constants.ADMIN);
for (ResourcePolicy resourcePolicy : policiesAdmin) {
if (resourcePolicyService.isDateValid(resourcePolicy)) {
String fieldValue;
if (resourcePolicy.getGroup() != null) {
// We have a group add it to the value
fieldValue = "g" + resourcePolicy.getGroup().getID();
} else {
// We have an eperson add it to the value
fieldValue = "e" + resourcePolicy.getEPerson().getID();
}
document.addField("read", fieldValue);
document.addField("admin", fieldValue);
}
// remove the policy from the cache to save memory
context.uncacheEntity(resourcePolicy);
}
}
dso = ContentServiceFactory.getInstance().getDSpaceObjectService(dso).getParentObject(context, dso);
}
} catch (SQLException e) {
log.error(LogHelper.getHeader(context, "Error while indexing resource policies", "DSpace object: (id " + dso.getID() + " type " + dso.getType() + ")"));
}
}
}
use of org.dspace.content.Community in project DSpace by DSpace.
the class ITDSpaceAIP method testRestoreRestrictedCommunity.
/**
* Test restoration from AIP of an access restricted Community
*/
@Test
public void testRestoreRestrictedCommunity() throws Exception {
log.info("testRestoreRestrictedCommunity() - BEGIN");
// Locate the top-level Community (as a parent)
Community parent = (Community) handleService.resolveToObject(context, topCommunityHandle);
// Create a brand new (empty) Community to test with
Community community = communityService.createSubcommunity(context, parent);
communityService.addMetadata(context, community, "dc", "title", null, null, "Restricted Community");
communityService.update(context, community);
String communityHandle = community.getHandle();
// Create a new Group to access restrict to
Group group = groupService.create(context);
groupService.setName(group, "Special Users");
groupService.update(context, group);
// Create a custom resource policy for this community
List<ResourcePolicy> policies = new ArrayList<>();
ResourcePolicy policy = resourcePolicyService.create(context);
policy.setRpName("Special Read Only");
policy.setGroup(group);
policy.setAction(Constants.READ);
policies.add(policy);
// Replace default community policies with this new one
authorizeService.removeAllPolicies(context, community);
authorizeService.addPolicies(context, policies, community);
// Export collection AIP
log.info("testRestoreRestrictedCommunity() - CREATE Community AIP");
File aipFile = createAIP(community, null, false);
// Now, delete that Collection
log.info("testRestoreRestrictedCommunity() - DELETE Community");
communityService.removeSubcommunity(context, parent, community);
// Assert the deleted collection no longer exists
DSpaceObject obj = handleService.resolveToObject(context, communityHandle);
assertThat("testRestoreRestrictedCommunity() Community " + communityHandle + " doesn't exist", obj, nullValue());
// Restore Collection from AIP (non-recursive)
log.info("testRestoreRestrictedCommunity() - RESTORE Community");
restoreFromAIP(parent, aipFile, null, false);
// Assert the deleted Collection is RESTORED
DSpaceObject objRestored = handleService.resolveToObject(context, communityHandle);
assertThat("testRestoreRestrictedCommunity() Community " + communityHandle + " exists", objRestored, notNullValue());
// Assert the number of restored policies is equal
List<ResourcePolicy> policiesRestored = authorizeService.getPolicies(context, objRestored);
assertEquals("testRestoreRestrictedCommunity() restored policy count equal", policies.size(), policiesRestored.size());
// Assert the restored policy has same name, group and permission settings
ResourcePolicy restoredPolicy = policiesRestored.get(0);
assertEquals("testRestoreRestrictedCommunity() restored policy group successfully", policy.getGroup().getName(), restoredPolicy.getGroup().getName());
assertEquals("testRestoreRestrictedCommunity() restored policy action successfully", policy.getAction(), restoredPolicy.getAction());
assertEquals("testRestoreRestrictedCommunity() restored policy name successfully", policy.getRpName(), restoredPolicy.getRpName());
log.info("testRestoreRestrictedCommunity() - END");
}
Aggregations