/* * Insert the relation between two metadata records. * If it already exist, bypass insert statement and an alreadyExist flag. * * @see jeeves.interfaces.Service#exec(org.jdom.Element, * jeeves.server.context.ServiceContext) Parameter name: parentId - Parent * metadata identifier Parameter name: childId - Child metadata identifier */ public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception { int parentId = Integer.parseInt( Utils.getIdentifierFromParameters( params, context, Params.PARENT_UUID, Params.PARENT_ID)); int childId = Integer.parseInt( Utils.getIdentifierFromParameters(params, context, Params.CHILD_UUID, Params.CHILD_ID)); Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); String query = "Select count(*) as exist from Relations where id=? and relatedId=?"; Element record = dbms.select(query, parentId, childId).getChild("record"); boolean exist = false; if (record.getChild("exist").getText().equals("1")) { exist = true; } else { // Add new relation query = "INSERT INTO Relations (id, relatedId) " + "VALUES (?, ?)"; dbms.execute(query, parentId, childId); } Element response = new Element(Jeeves.Elem.RESPONSE) .setAttribute("alreadyExist", String.valueOf(exist)) .addContent(new Element("parentId").setText(String.valueOf(parentId))) .addContent(new Element("childId").setText(String.valueOf(childId))); return response; }
public Element exec(Element params, ServiceContext context) throws Exception { Element response = new Element("response"); Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); // --- check access GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); DataManager dm = gc.getDataManager(); boolean addEdit = false; // --- the request should contain an ID or UUID String id = Utils.getIdentifierFromParameters(params, context); if (id == null) { throw new MetadataNotFoundEx("No record has this UUID"); } // --- check download access Lib.resource.checkPrivilege(context, id, AccessManager.OPER_DOWNLOAD); // --- get metadata boolean withValidationErrors = false, keepXlinkAttributes = false; Element elMd = gc.getDataManager() .getMetadata(context, id, addEdit, withValidationErrors, keepXlinkAttributes); if (elMd == null) throw new MetadataNotFoundEx("Metadata not found - deleted?"); response.addContent(new Element("id").setText(id)); // --- transform record into brief version String briefXslt = appPath + "xsl/metadata-brief.xsl"; Element elBrief = Xml.transform(elMd, briefXslt); XPath xp; List elems; // --- process links to a file (have name field not blank) // --- if they are a reference to a downloadable local file then get size // --- and date modified, if not then set local to false xp = XPath.newInstance("link[starts-with(@protocol,'WWW:DOWNLOAD') and @name!='']"); elems = xp.selectNodes(elBrief); response = processDownloadLinks(context, id, dm.getSiteURL(), elems, response); // --- now process web links so that they can be displayed as well xp = XPath.newInstance("link[starts-with(@protocol,'WWW:LINK')]"); elems = xp.selectNodes(elBrief); response = processWebLinks(elems, response); return response; }
public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception { String id = Utils.getIdentifierFromParameters(params, context); String filename = Util.getParam(params, Params.FILENAME); String access = Util.getParam(params, Params.ACCESS); Lib.resource.checkEditPrivilege(context, id); // delete the file File dir = new File(Lib.resource.getDir(context, access, id)); File file = new File(dir, filename); if (file.exists() && !file.delete()) throw new OperationAbortedEx("unable to delete resource"); Element response = new Element(Jeeves.Elem.RESPONSE).addContent(new Element(Geonet.Elem.ID).setText(id)); return response; }
public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception { GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); DataManager dataMan = gc.getBean(DataManager.class); AccessManager accessMan = gc.getBean(AccessManager.class); Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); String id = Utils.getIdentifierFromParameters(params, context); // ----------------------------------------------------------------------- // --- check access MdInfo info = dataMan.getMetadataInfo(dbms, id); if (info == null) throw new IllegalArgumentException("Metadata not found --> " + id); if (!accessMan.canEdit(context, id)) throw new OperationNotAllowedEx(); // ----------------------------------------------------------------------- // --- backup metadata in 'removed' folder if (info.template != MdInfo.Template.SUBTEMPLATE) backupFile( context, id, info.uuid, MEFLib.doExport(context, info.uuid, "full", false, true, false)); // ----------------------------------------------------------------------- // --- remove the metadata directory including the public and private directories. File pb = new File(Lib.resource.getMetadataDir(context, id)); FileCopyMgr.removeDirectoryOrFile(pb); // ----------------------------------------------------------------------- // --- delete metadata and return status dataMan.deleteMetadata(context, dbms, id); Element elResp = new Element(Jeeves.Elem.RESPONSE); elResp.addContent(new Element(Geonet.Elem.ID).setText(id)); return elResp; }
public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception { GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); DataManager dataMan = gc.getDataManager(); Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); UserSession session = context.getUserSession(); String id = Utils.getIdentifierFromParameters(params, context); // --- validate metadata from session Element errorReport = new AjaxEditUtils(context) .validateMetadataEmbedded(session, dbms, id, context.getLanguage()); // --- update element and return status Element elResp = new Element(Jeeves.Elem.RESPONSE); elResp.addContent(new Element(Geonet.Elem.ID).setText(id)); elResp.addContent(new Element("schema").setText(dataMan.getMetadataSchema(dbms, id))); elResp.addContent(errorReport); return elResp; }
public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception { AjaxEditUtils ajaxEditUtils = new AjaxEditUtils(context); ajaxEditUtils.preprocessUpdate(params, context); GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); DataManager dataMan = gc.getBean(DataManager.class); UserSession session = context.getUserSession(); Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); String id = Utils.getIdentifierFromParameters(params, context); String isTemplate = Util.getParam(params, Params.TEMPLATE, "n"); String showValidationErrors = Util.getParam(params, Params.SHOWVALIDATIONERRORS, "false"); String title = params.getChildText(Params.TITLE); String data = params.getChildText(Params.DATA); String minor = Util.getParam(params, Params.MINOREDIT, "false"); boolean finished = config.getValue(Params.FINISHED, "no").equals("yes"); boolean forget = config.getValue(Params.FORGET, "no").equals("yes"); if (!forget) { int iLocalId = Integer.parseInt(id); dataMan.setTemplateExt(dbms, iLocalId, isTemplate, title); // --- use StatusActionsFactory and StatusActions class to possibly // --- change status as a result of this edit (use onEdit method) StatusActionsFactory saf = new StatusActionsFactory(gc.getStatusActionsClass()); StatusActions sa = saf.createStatusActions(context, dbms); saf.onEdit(sa, iLocalId, minor.equals("true")); if (data != null) { Element md = Xml.loadString(data, false); String changeDate = null; boolean validate = showValidationErrors.equals("true"); boolean updateDateStamp = !minor.equals("true"); boolean ufo = true; boolean index = true; if (!dataMan.updateMetadata( context, dbms, id, md, validate, ufo, index, context.getLanguage(), changeDate, updateDateStamp)) { throw new ConcurrentUpdateEx(id); } } else { ajaxEditUtils.updateContent(params, false, true); } } // ----------------------------------------------------------------------- // --- update element and return status Element elResp = new Element(Jeeves.Elem.RESPONSE); elResp.addContent(new Element(Geonet.Elem.ID).setText(id)); elResp.addContent(new Element(Geonet.Elem.SHOWVALIDATIONERRORS).setText(showValidationErrors)); boolean justCreated = Util.getParam(params, Params.JUST_CREATED, null) != null; if (justCreated) { elResp.addContent(new Element(Geonet.Elem.JUSTCREATED).setText("true")); } elResp.addContent(new Element(Params.MINOREDIT).setText(minor)); // --- if finished then remove the XML from the session if (finished) { ajaxEditUtils.removeMetadataEmbedded(session, id); } return elResp; }
public Element exec(Element params, ServiceContext context) throws Exception { UserSession session = context.getUserSession(); boolean witholdWithheldElements = Util.getParam(params, "hide_withheld", false); if (witholdWithheldElements) { XmlSerializer.getThreadLocal(true).setForceHideWithheld(witholdWithheldElements); } // ----------------------------------------------------------------------- // --- handle current tab Element elCurrTab = params.getChild(Params.CURRTAB); if (elCurrTab != null) session.setProperty(Geonet.Session.METADATA_SHOW, elCurrTab.getText()); // ----------------------------------------------------------------------- // --- check access GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); DataManager dm = gc.getDataManager(); String id = Utils.getIdentifierFromParameters(params, context); if (!skipPopularity) { // skipPopularity could be a URL param as well String skip = Util.getParam(params, "skipPopularity", "n"); skipPopularity = skip.equals("y"); } if (id == null) throw new MetadataNotFoundEx("Metadata not found."); Lib.resource.checkPrivilege(context, id, AccessManager.OPER_VIEW); // ----------------------------------------------------------------------- // --- get metadata Element elMd; boolean addEditing = false; if (!skipInfo) { boolean withValidationErrors = false, keepXlinkAttributes = false; elMd = dm.getMetadata(context, id, addEditing, withValidationErrors, keepXlinkAttributes); } else { elMd = dm.getMetadataNoInfo(context, id); } if (elMd == null) throw new MetadataNotFoundEx(id); if (addRefs) { // metadata.show for GeoNetwork needs geonet:element elMd = dm.enumerateTree(elMd); } // // setting schemaLocation // TODO currently it's only set for ISO metadata - this should all move // to // the updatefixedinfo.xsl for each schema // do not set schemaLocation if it is already there if (elMd.getAttribute("schemaLocation", Csw.NAMESPACE_XSI) == null) { Namespace gmdNs = elMd.getNamespace("gmd"); // document has ISO root element and ISO namespace if (gmdNs != null && gmdNs.getURI().equals("http://www.isotc211.org/2005/gmd")) { String schemaLocation; // if document has srv namespace then add srv schemaLocation if (elMd.getNamespace("srv") != null) { schemaLocation = " http://www.isotc211.org/2005/srv http://schemas.opengis.net/iso/19139/20060504/srv/srv.xsd"; } // otherwise add gmd schemaLocation // (but not both! as that is invalid, the schemas describe // partially the same schema types) else { schemaLocation = "http://www.isotc211.org/2005/gmd http://www.isotc211.org/2005/gmd/gmd.xsd"; } Attribute schemaLocationA = new Attribute("schemaLocation", schemaLocation, Csw.NAMESPACE_XSI); elMd.setAttribute(schemaLocationA); } } // --- increase metadata popularity if (!skipPopularity) dm.increasePopularity(context, id); return elMd; }
public Element exec(Element params, ServiceContext context) throws Exception { GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); DataManager dm = gc.getDataManager(); AccessManager am = gc.getAccessManager(); Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); String id = Utils.getIdentifierFromParameters(params, context); // ----------------------------------------------------------------------- // --- check access MdInfo info = dm.getMetadataInfo(dbms, id); if (info == null) throw new MetadataNotFoundEx(id); Element ownerId = new Element("ownerid").setText(info.owner); Element hasOwner = new Element("owner"); if (am.isOwner(context, id)) hasOwner.setText("true"); else hasOwner.setText("false"); // --- get all operations Element elOper = Lib.local.retrieve(dbms, "Operations").setName(Geonet.Elem.OPERATIONS); // ----------------------------------------------------------------------- // --- retrieve groups operations Set<String> userGroups = am.getUserGroups(dbms, context.getUserSession(), context.getIpAddress()); Element elGroup = Lib.local.retrieve(dbms, "Groups"); List list = elGroup.getChildren(); for (int i = 0; i < list.size(); i++) { Element el = (Element) list.get(i); el.setName(Geonet.Elem.GROUP); // --- get all operations that this group can do on given metadata String sGrpId = el.getChildText("id"); el.setAttribute("userGroup", userGroups.contains(sGrpId) ? "true" : "false"); String query = "SELECT operationId FROM OperationAllowed WHERE metadataId=? AND groupId=?"; List listAllow = dbms.select(query, id, sGrpId).getChildren(); // --- now extend the group list adding proper operations List listOper = elOper.getChildren(); for (int j = 0; j < listOper.size(); j++) { String operId = ((Element) listOper.get(j)).getChildText("id"); Element elGrpOper = new Element(Geonet.Elem.OPER).addContent(new Element(Geonet.Elem.ID).setText(operId)); boolean bFound = false; for (int k = 0; k < listAllow.size(); k++) { Element elAllow = (Element) listAllow.get(k); if (operId.equals(elAllow.getChildText("operationid"))) { bFound = true; break; } } if (bFound) elGrpOper.addContent(new Element(Geonet.Elem.ON)); el.addContent(elGrpOper); } } // ----------------------------------------------------------------------- // --- put all together Element elRes = new Element(Jeeves.Elem.RESPONSE) .addContent(new Element(Geonet.Elem.ID).setText(id)) .addContent(elOper) .addContent(elGroup) .addContent(ownerId) .addContent(hasOwner); return elRes; }