Skip to content

Commit

Permalink
Merge branch 'release-2017.02' into clarin
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarko committed Mar 29, 2017
2 parents 8bb548b + 57b4be7 commit 5a5d2bb
Show file tree
Hide file tree
Showing 28 changed files with 279 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private void validate_dc_type(Item item, Metadatum[] dcs, StringBuilder results)
Metadatum[] dcs_type = item.getMetadataByMetadataString("dc.type");
// no metadata?
if ( dcs_type == null || dcs_type.length == 0) {
throw new CurateException("Does not dc.type metadata",
throw new CurateException("Does not have dc.type metadata",
Curator.CURATE_FAIL );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
import org.dspace.health.ReportInfo;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;

public class AdditionalInfoCheck extends Check {

public static final String beancountersPath = "/proc/user_beancounters";

@Override
public String run( ReportInfo ri ) {
String ret = "";
Expand Down Expand Up @@ -54,9 +58,11 @@ public String run( ReportInfo ri ) {
ret +=
"Clarin centers: https://centres.clarin.eu/\n";

ret += IOUtils.run(
new File(ConfigurationManager.getProperty("dspace.dir")),
new String[]{"sudo", "cat", "/proc/user_beancounters"});
if(Files.exists(Paths.get(beancountersPath))) {
ret += IOUtils.run(
new File(ConfigurationManager.getProperty("dspace.dir")),
new String[]{"sudo", "cat", beancountersPath});
}

return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ public boolean accept(File dir, String name) {
org.apache.commons.io.IOUtils.copy(
new URL(ConfigurationManager.getProperty("dspace.url")
+ "/discojuice/feeds").openStream(), writer);
String jsonp = writer.toString();
String json = writer.toString();
// end download
String json = jsonp.substring(jsonp.indexOf("(") + 1,
jsonp.lastIndexOf(")")); // strip the dj_md_1()
Set<String> entities = new HashSet<String>();
JSONParser parser = new JSONParser();
JSONArray entityArray = (JSONArray) parser.parse(json);
Expand Down
13 changes: 7 additions & 6 deletions dspace-api/src/main/java/org/dspace/health/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ public static String getTypeXcollectionCounts() throws SQLException {
StringBuilder ret = new StringBuilder();
Map<String, Map<String, Integer>> table = new HashMap<>();
Set<String> colnames = new HashSet<>();
int lenColname = 0;
int lenColname = 1;
Context context = new Context();
TableRowIterator rows = DatabaseManager.query(context,
"SELECT text_value AS type, colname, count(text_value) AS count FROM item JOIN metadatavalue ON item_id=resource_id " +
"NATURAL JOIN metadatafieldregistry NATURAL JOIN metadataschemaregistry JOIN " +
"(SELECT resource_id, text_value AS colname FROM metadatavalue NATURAL JOIN metadatafieldregistry NATURAL JOIN metadataschemaregistry "+
"SELECT text_value AS type, colname, count(*) AS count FROM metadatavalue " +
"NATURAL JOIN metadatafieldregistry NATURAL JOIN metadataschemaregistry " +
"RIGHT JOIN item ON item_id=resource_id AND resource_type_id=? AND short_id='dc' AND element='type' AND withdrawn=false AND in_archive=true " +
"JOIN (SELECT resource_id, text_value AS colname FROM metadatavalue NATURAL JOIN metadatafieldregistry NATURAL JOIN metadataschemaregistry "+
"WHERE short_id='dc' AND element='title' AND qualifier IS NULL AND resource_type_id=?) " +
"AS colnames ON colnames.resource_id=owning_collection " +
"WHERE resource_type_id=? AND short_id='dc' AND element='type' AND withdrawn=false AND in_archive=true GROUP BY text_value, colname;",
Constants.COLLECTION, Constants.ITEM);
"GROUP BY text_value, colname;",
Constants.ITEM, Constants.COLLECTION);
for(TableRow row : rows.toList()){
String type = row.getStringColumn("type");
String colname = row.getStringColumn("colname");
Expand Down
6 changes: 5 additions & 1 deletion dspace-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<properties>
<!-- This is the path to the root [dspace-src] directory. -->
<root.basedir>${basedir}/..</root.basedir>
<jersey.version>2.21</jersey.version>
<jersey.version>2.25.1</jersey.version>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -101,6 +101,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down
19 changes: 9 additions & 10 deletions dspace-rest/src/main/java/org/dspace/rest/BitstreamResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.BitstreamFormat;
import org.dspace.content.Bundle;
import org.dspace.eperson.Group;
import org.dspace.rest.common.Bitstream;
import org.dspace.rest.common.ResourcePolicy;
Expand Down Expand Up @@ -97,7 +96,7 @@ public Bitstream getBitstream(@PathParam("bitstream_id") Integer bitstreamId, @Q

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);

writeStats(dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers,
Expand Down Expand Up @@ -150,7 +149,7 @@ public ResourcePolicy[] getBitstreamPolicies(@PathParam("bitstream_id") Integer

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
AuthorizeManager.getPolicies(context, dspaceBitstream);

Expand Down Expand Up @@ -212,7 +211,7 @@ public Bitstream[] getBitstreams(@QueryParam("expand") String expand,

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Bitstream[] dspaceBitstreams = org.dspace.content.Bitstream.findAll(context);

if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
Expand Down Expand Up @@ -295,7 +294,7 @@ public javax.ws.rs.core.Response getBitstreamData(@PathParam("bitstream_id") Int

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);

writeStats(dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers,
Expand Down Expand Up @@ -367,7 +366,7 @@ public javax.ws.rs.core.Response addBitstreamPolicy(@PathParam("bitstream_id") I

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);

writeStats(dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor, headers,
Expand Down Expand Up @@ -437,7 +436,7 @@ public Response updateBitstream(@PathParam("bitstream_id") Integer bitstreamId,

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);

writeStats(dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
Expand Down Expand Up @@ -539,7 +538,7 @@ public Response updateBitstreamData(@PathParam("bitstream_id") Integer bitstream

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);

writeStats(dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
Expand Down Expand Up @@ -623,7 +622,7 @@ public Response deleteBitstream(@PathParam("bitstream_id") Integer bitstreamId,

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.DELETE);

writeStats(dspaceBitstream, UsageEvent.Action.DELETE, user_ip, user_agent, xforwardedfor,
Expand Down Expand Up @@ -689,7 +688,7 @@ public javax.ws.rs.core.Response deleteBitstreamPolicy(@PathParam("bitstream_id"

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);

writeStats(dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor, headers,
Expand Down
49 changes: 23 additions & 26 deletions dspace-rest/src/main/java/org/dspace/rest/CollectionsResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@
import org.dspace.authorize.AuthorizeManager;
import org.dspace.browse.BrowseException;
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.identifier.IdentifierException;
import org.dspace.identifier.IdentifierService;
import org.dspace.rest.common.Collection;
import org.dspace.rest.common.Item;
import org.dspace.rest.common.MetadataEntry;
import org.dspace.rest.exceptions.ContextException;
import org.dspace.usage.UsageEvent;
import org.dspace.utils.DSpace;

/**
* This class provides all CRUD operation over collections.
Expand Down Expand Up @@ -96,7 +100,7 @@ public org.dspace.rest.common.Collection getCollection(@PathParam("collection_id

try
{
context = createContext(getUser(headers));
context = createContext(headers);

org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId, org.dspace.core.Constants.READ);
writeStats(dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
Expand Down Expand Up @@ -165,7 +169,7 @@ public org.dspace.rest.common.Collection[] getCollections(@QueryParam("expand")

try
{
context = createContext(getUser(headers));
context = createContext(headers);

if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
{
Expand Down Expand Up @@ -251,7 +255,7 @@ public org.dspace.rest.common.Item[] getCollectionItems(@PathParam("collection_i

try
{
context = createContext(getUser(headers));
context = createContext(headers);

org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId, org.dspace.core.Constants.READ);
writeStats(dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
Expand Down Expand Up @@ -334,11 +338,11 @@ public Item addCollectionItem(@PathParam("collection_id") Integer collectionId,

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId,
org.dspace.core.Constants.WRITE);
org.dspace.core.Constants.ADD);

writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
writeStats(dspaceCollection, UsageEvent.Action.ADD, user_ip, user_agent, xforwardedfor,
headers, request, context);

log.trace("Creating item in collection(id=" + collectionId + ").");
Expand All @@ -362,6 +366,11 @@ public Item addCollectionItem(@PathParam("collection_id") Integer collectionId,
browse.indexItem(dspaceItem);

log.trace("Installing item to collection(id=" + collectionId + ").");
IdentifierService identifierService = new DSpace().getSingletonService(IdentifierService.class);
context.turnOffAuthorisationSystem();
identifierService.reserve(context, dspaceItem);
dspaceItem.update();
context.restoreAuthSystemState();
dspaceItem = org.dspace.content.InstallItem.installItem(context, workspaceItem);

returnItem = new Item(dspaceItem, "", context);
Expand Down Expand Up @@ -391,8 +400,9 @@ public Item addCollectionItem(@PathParam("collection_id") Integer collectionId,
processException(
"Could not add item into collection(id=" + collectionId + "), ContextException. Message: " + e.getMessage(),
context);
}
finally
} catch (IdentifierException e) {
processException("Could not reserve handle, IdentifierException. Message: " + e.getMessage(), context);
} finally
{
processFinally(context);
}
Expand Down Expand Up @@ -434,7 +444,7 @@ public Response updateCollection(@PathParam("collection_id") Integer collectionI

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId,
org.dspace.core.Constants.WRITE);

Expand Down Expand Up @@ -506,7 +516,7 @@ public Response deleteCollection(@PathParam("collection_id") Integer collectionI

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId,
org.dspace.core.Constants.DELETE);

Expand Down Expand Up @@ -577,9 +587,9 @@ public Response deleteCollectionItem(@PathParam("collection_id") Integer collect

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId,
org.dspace.core.Constants.WRITE);
Constants.REMOVE);

org.dspace.content.Item item = null;
org.dspace.content.ItemIterator dspaceItems = dspaceCollection.getItems();
Expand All @@ -598,19 +608,6 @@ public Response deleteCollectionItem(@PathParam("collection_id") Integer collect
log.warn("Item(id=" + itemId + ") was not found!");
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
else if (!AuthorizeManager.authorizeActionBoolean(context, item, org.dspace.core.Constants.REMOVE))
{
context.abort();
if (context.getCurrentUser() != null)
{
log.error("User(" + context.getCurrentUser().getEmail() + ") has not permission to delete item!");
}
else
{
log.error("User(anonymous) has not permission to delete item!");
}
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}

writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
headers, request, context);
Expand Down Expand Up @@ -674,7 +671,7 @@ public Collection findCollectionByName(String name, @Context HttpHeaders headers

try
{
context = createContext(getUser(headers));
context = createContext(headers);
org.dspace.content.Collection[] dspaceCollections;

dspaceCollections = org.dspace.content.Collection.findAll(context);
Expand Down
Loading

0 comments on commit 5a5d2bb

Please sign in to comment.