Fixed moderation bugs
This commit is contained in:
parent
dda7bf6234
commit
bdb930092f
|
@ -255,7 +255,15 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
if(objectNode.has(PRIVATE_KEY)) {
|
if(objectNode.has(PRIVATE_KEY)) {
|
||||||
boolean privatePackage = objectNode.get(PRIVATE_KEY).asBoolean();
|
boolean privatePackage = objectNode.get(PRIVATE_KEY).asBoolean();
|
||||||
if(privatePackage) {
|
if(privatePackage) {
|
||||||
objectNode.put(SEARCHABLE_KEY, true);
|
/*
|
||||||
|
* This version is not properly managed by CKAN.
|
||||||
|
* It is converted to:
|
||||||
|
* searchable: "true"
|
||||||
|
* which is incidentally considered as true value even is not correct.
|
||||||
|
* We need to provide a string with T as capitol letters to make it working
|
||||||
|
* objectNode.put(SEARCHABLE_KEY, true);
|
||||||
|
*/
|
||||||
|
objectNode.put(SEARCHABLE_KEY, "True");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,6 +804,12 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
try {
|
try {
|
||||||
JsonNode jsonNode = validateJson(json);
|
JsonNode jsonNode = validateJson(json);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Going to read the item from CKAN just to check the item status.
|
||||||
|
* I need to reset the result first because the current contains
|
||||||
|
* the extras as sent by the client which are not trusted
|
||||||
|
*/
|
||||||
|
this.result = null;
|
||||||
readItem();
|
readItem();
|
||||||
|
|
||||||
jsonNode = checkModerationUpdate(jsonNode);
|
jsonNode = checkModerationUpdate(jsonNode);
|
||||||
|
@ -1010,7 +1024,7 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
// The item was published before activating the moderation.
|
// The item was published before activating the moderation.
|
||||||
// The item is considered as approved and the item representation must be updated
|
// The item is considered as approved and the item representation must be updated
|
||||||
setToApproved(result);
|
setToApproved(result);
|
||||||
String ret = sendPostRequest(ITEM_PATCH, getAsString(result));
|
String ret = sendPostRequest(ITEM_UPDATE, getAsString(result));
|
||||||
try {
|
try {
|
||||||
result = mapper.readTree(ret);
|
result = mapper.readTree(ret);
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
@ -1237,7 +1251,15 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
addExtraField(jsonNode, Moderated.SYSTEM_CM_ITEM_VISIBILITY, cmItemVisibility.getValue());
|
addExtraField(jsonNode, Moderated.SYSTEM_CM_ITEM_VISIBILITY, cmItemVisibility.getValue());
|
||||||
|
|
||||||
((ObjectNode) jsonNode).put(PRIVATE_KEY, true);
|
((ObjectNode) jsonNode).put(PRIVATE_KEY, true);
|
||||||
((ObjectNode) jsonNode).put(SEARCHABLE_KEY, false);
|
/*
|
||||||
|
* This version is not properly managed by CKAN.
|
||||||
|
* It is converted to:
|
||||||
|
* searchable: "false"
|
||||||
|
* which is considered as true value.
|
||||||
|
* We need to provide a string with F as capitol letters to make it working
|
||||||
|
* ((ObjectNode) jsonNode).put(SEARCHABLE_KEY, false);
|
||||||
|
*/
|
||||||
|
((ObjectNode) jsonNode).put(SEARCHABLE_KEY, "False");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1268,8 +1290,13 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
((ObjectNode) jsonNode).put(PRIVATE_KEY, cmItemVisibility == CMItemVisibility.RESTRICTED ? true :false);
|
boolean privateItem = cmItemVisibility == CMItemVisibility.RESTRICTED ? true :false;
|
||||||
((ObjectNode) jsonNode).put(SEARCHABLE_KEY, true);
|
((ObjectNode) jsonNode).put(PRIVATE_KEY, privateItem);
|
||||||
|
if(privateItem) {
|
||||||
|
((ObjectNode) jsonNode).put(SEARCHABLE_KEY, "True");
|
||||||
|
}else {
|
||||||
|
((ObjectNode) jsonNode).remove(SEARCHABLE_KEY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postItemCreated() throws Exception {
|
private void postItemCreated() throws Exception {
|
||||||
|
@ -1317,7 +1344,7 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
throw new MethodNotSupportedException("Only catalogue moderator can approve a pending item.");
|
throw new MethodNotSupportedException("Only catalogue moderator can approve a pending item.");
|
||||||
}
|
}
|
||||||
setToApproved(result);
|
setToApproved(result);
|
||||||
String ret = sendPostRequest(ITEM_PATCH, getAsString(result));
|
String ret = sendPostRequest(ITEM_UPDATE, getAsString(result));
|
||||||
result = mapper.readTree(ret);
|
result = mapper.readTree(ret);
|
||||||
|
|
||||||
moderationThread.setItemCoordinates(itemID, name);
|
moderationThread.setItemCoordinates(itemID, name);
|
||||||
|
|
|
@ -585,7 +585,11 @@ public class CKANPackageTest extends ContextTest {
|
||||||
JsonNode readItemObjectNode = mapper.readTree(readItem);
|
JsonNode readItemObjectNode = mapper.readTree(readItem);
|
||||||
String updatedNotes = "A research of Luca Frosini made during the PhD";
|
String updatedNotes = "A research of Luca Frosini made during the PhD";
|
||||||
((ObjectNode) readItemObjectNode).put(NOTES_KEY, updatedNotes);
|
((ObjectNode) readItemObjectNode).put(NOTES_KEY, updatedNotes);
|
||||||
ckanPackage.update(mapper.writeValueAsString(readItemObjectNode));
|
String ret = ckanPackage.update(mapper.writeValueAsString(readItemObjectNode));
|
||||||
|
logger.debug("Updated {}", ret);
|
||||||
|
|
||||||
|
ckanPackage = new CKANPackage();
|
||||||
|
ckanPackage.setName(ITEM_NAME_VALUE);
|
||||||
ckanPackage.message("I hope now it can be approved.");
|
ckanPackage.message("I hope now it can be approved.");
|
||||||
|
|
||||||
|
|
||||||
|
@ -630,16 +634,16 @@ public class CKANPackageTest extends ContextTest {
|
||||||
// logger.debug("{}", res);
|
// logger.debug("{}", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
// @Ignore
|
||||||
// @Test
|
@Test
|
||||||
public void deleteAllItemsInAllOrganizations() {
|
public void deleteAllItemsInAllOrganizations() {
|
||||||
CKANPackage ckanPackage = new CKANPackage();
|
CKANPackage ckanPackage = new CKANPackage();
|
||||||
MultivaluedMap<String, String> mvm = new MultivaluedHashMap<String,String>();
|
MultivaluedMap<String, String> mvm = new MultivaluedHashMap<String,String>();
|
||||||
mvm.add(GCatConstants.OWN_ONLY_QUERY_PARAMETER, "false");
|
mvm.add(GCatConstants.OWN_ONLY_QUERY_PARAMETER, "false");
|
||||||
UriInfo uriInfo = getUriInfo(mvm);
|
UriInfo uriInfo = getUriInfo(mvm);
|
||||||
ckanPackage.setUriInfo(uriInfo);
|
ckanPackage.setUriInfo(uriInfo);
|
||||||
// String res = ckanPackage.deleteAll(true);
|
String res = ckanPackage.deleteAll(true);
|
||||||
// logger.debug("{}", res);
|
logger.debug("{}", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue