git-svn-id: http://svn.research-infrastructures.eu/d4science/gcube/trunk/spatial-data/geonetwork@135174 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b7e289dc05
commit
b977d20fc4
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Resource version="0.4.x">
|
||||
<ID>060088db-2045-45e5-be70-2709b0d9d0de</ID>
|
||||
<Type>RuntimeResource</Type>
|
||||
<Profile>
|
||||
<Category>Gis</Category>
|
||||
<Platform>
|
||||
<Name>geonetwork</Name>
|
||||
<Version>3</Version>
|
||||
<MinorVersion>2</MinorVersion>
|
||||
<RevisionVersion>1</RevisionVersion>
|
||||
<BuildVersion>5</BuildVersion>
|
||||
</Platform>
|
||||
<RunTime>
|
||||
<HostedOn>node3-d-d4s.d4science.org</HostedOn>
|
||||
<Status>READY</Status>
|
||||
</RunTime>
|
||||
<AccessPoint>
|
||||
<Interface>
|
||||
<Endpoint EntryName="geonetwork">http://node3-d-d4s.d4science.org/geonetwork</Endpoint>
|
||||
</Interface>
|
||||
<AccessData>
|
||||
<Username>admin</Username>
|
||||
<Password>5jykeFZrlF1Xfa4vohyDYg==</Password>
|
||||
</AccessData>
|
||||
<Properties>
|
||||
<Property>
|
||||
<Name>priority</Name>
|
||||
<Value encrypted="false">1</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>default1</Name>
|
||||
<Value encrypted="false">858</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>scopePwd1</Name>
|
||||
<Value encrypted="true">IttLsIsLWcjT0VFks4o89Q==</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>priority</Name>
|
||||
<Value encrypted="false">1</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>suffixes</Name>
|
||||
<Value encrypted="false">1</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>ckanUser1</Name>
|
||||
<Value encrypted="false">FjbBwWw</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>ckanPwd1</Name>
|
||||
<Value encrypted="true">6zQtKXloLczK2amphRXXmw==</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>private1</Name>
|
||||
<Value encrypted="false">857</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>public1</Name>
|
||||
<Value encrypted="false">858</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>scope1</Name>
|
||||
<Value encrypted="false">gcube</Value>
|
||||
</Property>
|
||||
<Property>
|
||||
<Name>scopeUser1</Name>
|
||||
<Value encrypted="false">mUAKFMh</Value>
|
||||
</Property>
|
||||
</Properties>
|
||||
</AccessPoint>
|
||||
</Profile>
|
||||
</Resource>
|
|
@ -49,7 +49,10 @@ public class GNClientExtension implements GNClient {
|
|||
|
||||
|
||||
public Set<Group> getGroups() throws GNLibException, GNServerException{
|
||||
return GroupUtils.parseGroupXMLResponse(GNMetadataAdminExtension.getGroups(getConnection(), access));
|
||||
String groupResponse=GNMetadataAdminExtension.getGroups(getConnection(), access);
|
||||
if(access.getVersion().equals(Version.DUE))
|
||||
return GroupUtils.parseGroupXMLResponse(groupResponse);
|
||||
else return GroupUtils.parseUserJSONResponse(groupResponse);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ public class GNMetadataAdminExtension {
|
|||
|
||||
private final static String USER_3="/srv/api/0.1/users";
|
||||
private final static String GROUPS_3="/srv/api/0.1/groups";
|
||||
|
||||
|
||||
|
||||
|
||||
private final static String CREATE_GROUP_METHOD_2="/srv/en/group.update";
|
||||
|
||||
private final static String GROUP_LIST_METHOD="/srv/en/xml.group.list";
|
||||
|
@ -89,9 +89,44 @@ public class GNMetadataAdminExtension {
|
|||
}
|
||||
|
||||
public static String editUser(HTTPUtils connection,ServerAccess access,User toAdd, Collection<Integer> groups)throws GNLibException, GNServerException {
|
||||
log.debug("Couplign user {} to groups {} ",toAdd,groups);
|
||||
Element request=buildUpdateUserRequest(toAdd.getId(), toAdd.getUsername(), toAdd.getPassword(), toAdd.getProfile(), groups);
|
||||
return gnCall(connection,access,request,CREATE_USER_METHOD);
|
||||
log.debug("Coupling user {} to groups {} ",toAdd,groups);
|
||||
|
||||
Object request=null;
|
||||
String method=null;
|
||||
if(access.getVersion().equals(Version.DUE)){
|
||||
Element requestEl = new Element("request");
|
||||
requestEl.addContent(new Element("operation").setText("editinfo"));
|
||||
requestEl.addContent(new Element("id").setText(toAdd.getId()+""));
|
||||
requestEl.addContent(new Element("username").setText(toAdd.getUsername()));
|
||||
requestEl.addContent(new Element("password").setText(toAdd.getPassword()));
|
||||
requestEl.addContent(new Element("profile").setText(toAdd.getProfile().name()));
|
||||
if(groups!=null){
|
||||
for(Integer groupId:groups)requestEl.addContent(new Element("groups").setText(groupId+""));
|
||||
}
|
||||
request=requestEl;
|
||||
method=CREATE_USER_METHOD;
|
||||
}else{
|
||||
|
||||
try{
|
||||
JSONObject object=new JSONObject();
|
||||
object.put("username", toAdd.getUsername());
|
||||
object.put("password", toAdd.getPassword());
|
||||
object.put("profile",toAdd.getProfile().toString());
|
||||
object.put("enabled", true);
|
||||
if(groups!=null){
|
||||
JSONArray array=new JSONArray();
|
||||
for(Integer groupId:groups) array.put(groupId+"");
|
||||
object.put("groupsReviewer", array);
|
||||
}
|
||||
request= object;
|
||||
method=USER_3+"/"+toAdd.getId();
|
||||
}catch(Exception e){
|
||||
throw new GNLibException("Unabel to create JSON request for group creation ", e);
|
||||
}
|
||||
// request=buildUpdateUserRequest(toAdd.getId(), toAdd.getUsername(), toAdd.getPassword(), toAdd.getProfile(), groups);
|
||||
}
|
||||
|
||||
return gnCall(connection,access,request,method);
|
||||
}
|
||||
|
||||
public static String getUserGroupd(HTTPUtils connection,ServerAccess access,Integer userId)throws GNLibException, GNServerException {
|
||||
|
@ -228,24 +263,6 @@ public class GNMetadataAdminExtension {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @see {@link http://geonetwork-opensource.org/latest/developers/xml_services/metadata_xml_services.html#update-operations-allowed-for-a-metadata-metadata-admin }
|
||||
*/
|
||||
private static Element buildUpdateUserRequest(Integer id, String name, String password, Profile profile, Collection<Integer> groups) throws GNLibException {
|
||||
log.debug("Compiling admin request document");
|
||||
|
||||
Element request = new Element("request");
|
||||
request.addContent(new Element("operation").setText("editinfo"));
|
||||
request.addContent(new Element("id").setText(id+""));
|
||||
request.addContent(new Element("username").setText(name));
|
||||
request.addContent(new Element("password").setText(password));
|
||||
request.addContent(new Element("profile").setText(profile.name()));
|
||||
if(groups!=null){
|
||||
for(Integer groupId:groups)request.addContent(new Element("groups").setText(groupId+""));
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
private static Element buildSelectMetadata(List<Long> toSelectIds){
|
||||
|
|
|
@ -8,8 +8,12 @@ import javax.xml.xpath.XPath;
|
|||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.gcube.spatial.data.geonetwork.model.Group;
|
||||
import org.gcube.spatial.data.geonetwork.model.User;
|
||||
import org.gcube.spatial.data.geonetwork.model.User.Profile;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.input.SAXBuilder;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import it.geosolutions.geonetwork.exception.GNLibException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -42,53 +46,26 @@ public class GroupUtils {
|
|||
|
||||
}
|
||||
|
||||
|
||||
// public static Set<Group> parseGroupPage(String page) throws GNLibException{
|
||||
// try{
|
||||
// page=page.substring(page.indexOf("<div id=\"content_container\""),page.lastIndexOf("</div>")+("</div>").length());
|
||||
// page=page.replaceAll(" ", "");
|
||||
// HashSet<Group> toReturn=new HashSet<>();
|
||||
// String expression = "//table/tr/td/table";
|
||||
// InputSource inputSource = new InputSource(new StringReader(page));
|
||||
// Node tableNode = (Node) xpath.evaluate(expression, inputSource, XPathConstants.NODE);
|
||||
//
|
||||
// NodeList tableChildren=((Element)tableNode.getParentNode()).getElementsByTagName("tr");
|
||||
// for(int i=1;i<tableChildren.getLength();i++){ // starts from 1 to skip first row
|
||||
// Element tr=(Element)tableChildren.item(i);
|
||||
// NodeList tds=tr.getElementsByTagName("td");
|
||||
// String name=XMLUtils.getElementContent((Element)tds.item(0));
|
||||
// String description=XMLUtils.getElementContent((Element)tds.item(1));
|
||||
// String mail=XMLUtils.getElementContent((Element)tds.item(2));
|
||||
//
|
||||
// String idLink=((Element)tds.item(3)).getElementsByTagName("button").item(0).getAttributes().getNamedItem("onclick").getNodeValue();
|
||||
//
|
||||
// Integer id=parseGroupId(idLink);
|
||||
// toReturn.add(new Group(name,description,mail,id));
|
||||
//
|
||||
// }
|
||||
//
|
||||
// return toReturn;
|
||||
// }catch(XPathExpressionException e){
|
||||
// throw new GNLibException("Unable to parse response", e);
|
||||
// }
|
||||
// }
|
||||
|
||||
// private static Element parse(String s) throws GNLibException {
|
||||
// try {
|
||||
// SAXBuilder builder = new SAXBuilder();
|
||||
// return builder.build(new StringReader(s)).detachRootElement();
|
||||
// } catch (Exception ex) {
|
||||
// log.error("Error parsing GN response: " + s);
|
||||
// throw new GNLibException("Error parsing GN response: " + ex.getMessage(), ex);
|
||||
// }
|
||||
// }
|
||||
|
||||
// private static Integer parseGroupId(String tdContent){
|
||||
// Integer indexOfIdParameter=tdContent.indexOf("id=");
|
||||
// return Integer.parseInt(tdContent.substring(indexOfIdParameter+3, tdContent.indexOf("'", indexOfIdParameter)));
|
||||
// }
|
||||
|
||||
public static Set<Group> parseUserJSONResponse(String groupResponse) throws GNLibException {
|
||||
try{
|
||||
HashSet<Group> toReturn=new HashSet<>();
|
||||
JSONArray array=new JSONArray(groupResponse);
|
||||
for(int i=0;i<array.length();i++){
|
||||
JSONObject groupObj=array.getJSONObject(i);
|
||||
Integer id=groupObj.getInt("id");
|
||||
String name=groupObj.getString("name");
|
||||
String description=groupObj.getString("description");
|
||||
String email=groupObj.getString("email");
|
||||
|
||||
toReturn.add(new Group(name,description,email,id));
|
||||
}
|
||||
return toReturn;
|
||||
}catch(Exception e){
|
||||
throw new GNLibException("Unable to parse group JSON response ",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Group generateRandomGroup(Set<Group> existing, Integer nameLenght){
|
||||
Set<String> existingNames=new HashSet<>();
|
||||
|
@ -109,5 +86,8 @@ public class GroupUtils {
|
|||
if(g.getName().equals(toLookFor)) return g;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package org.gcube.spatial.data.geonetwork.test;
|
||||
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetworkAdministration;
|
||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||
|
||||
public class DeleteMeta {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
TokenSetter.set("/d4science.research-infrastructures.eu/gCubeApps/ProtectedAreaImpactMaps");
|
||||
GeoNetworkAdministration admin=GeoNetwork.get();
|
||||
admin.login(LoginLevel.ADMIN);
|
||||
for(long l=48986;l<=49005;l++){
|
||||
|
||||
admin.deleteMetadata(l);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue