Package org.fao.geonet.csw.common.exceptions

Examples of org.fao.geonet.csw.common.exceptions.NoApplicableCodeEx


            throw x;
        }
        catch(Exception x) {
            Log.error(Geonet.CSW_HARVEST, x.getMessage());
            x.printStackTrace();
            throw new NoApplicableCodeEx("ERROR: " + x.getMessage());
        }
  }
View Full Code Here


   
    Element filter = constr.getChild("Filter", Csw.NAMESPACE_OGC);
    Element cql = constr.getChild("CqlText", Csw.NAMESPACE_CSW);

    if (filter == null && cql == null)
      throw new NoApplicableCodeEx(
          "Missing filter expression or cql query");

    return (filter != null) ? filter : convertCQL(cql.getText());
  }
View Full Code Here

      Filter filter;
    try {
      filter = CQL.toFilter(cql);
    } catch (CQLException e) {
      Log.error(Geonet.CSW, "Error parsing CQL or during conversion into Filter");
      throw new NoApplicableCodeEx("Error during CQL to Filter conversion : "+ e);
    }

    final Configuration filter110Config = new OGCConfiguration();
    final Encoder encoder = new Encoder(filter110Config);
   
    final Charset charset = Charset.forName("UTF-16");
    encoder.setEncoding(charset);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
   
    String xml;
    try {
      encoder.encode(filter, OGC.Filter, out);
      xml = new String(out.toByteArray(), charset.toString());
    } catch (IOException e) {
      Log.error(Geonet.CSW, e.getMessage());
      throw new NoApplicableCodeEx("Error transforming Filter to XML" + e);
    }
   
        Element xmlFilter;
    try {
      xmlFilter = Xml.loadString(xml, false);
    } catch (Exception e) {
      Log.error(Geonet.CSW, "Error loading xml filter as jdom Element ");
      throw new NoApplicableCodeEx("Error loading xml filter as jdom Element " + e);
    }

        if(Log.isDebugEnabled(Geonet.CSW))
            Log.debug(Geonet.CSW, "Transformed CQL gives the following filter:\n"+Xml.getString(xmlFilter));
        
View Full Code Here

            return performSearch(context, luceneExpr, filterExpr, filterVersion, sort, resultType, startPosition, maxRecords,
                    maxHitsInSummary, cswServiceSpecificContraint, reader, indexAndTaxonomy.taxonomyReader);
        } catch (Exception e) {
      Log.error(Geonet.CSW_SEARCH, "Error while searching metadata ");
      Log.error(Geonet.CSW_SEARCH, "  (C) StackTrace:\n" + Util.getStackTrace(e));
      throw new NoApplicableCodeEx("Raised exception while searching metadata : " + e);
        } finally {
            try {
                if (indexAndTaxonomy != null) {
                    sm.releaseIndexReader(indexAndTaxonomy);
                }
View Full Code Here

    }
        catch (Exception e) {
      context.error("Error during Filter to Lucene conversion : " + e);
      context.error("  (C) StackTrace\n" + Util.getStackTrace(e));

      throw new NoApplicableCodeEx(
          "Error during Filter to Lucene conversion : " + e);
    }
  }
View Full Code Here

            }
        } catch (Exception e) {
            Log.error(Geonet.CSW, "Cannot process transaction");
            Log.error(Geonet.CSW, " (C) StackTrace\n" + Util.getStackTrace(e));

            throw new NoApplicableCodeEx("Cannot process transaction: " + e.getMessage());
        } finally {
            try {
                dataMan.indexMetadata(new ArrayList<String>(toIndex));
            } catch (Exception e) {
                Log.error(Geonet.CSW, "cannot index");
View Full Code Here

        // --- insert metadata into the system

        UserSession us = context.getUserSession();

        if (us.getUserId() == null)
            throw new NoApplicableCodeEx("User not authenticated.");

        Profile profile = us.getProfile();

        // Only editors and above are allowed to insert metadata
        if (profile != Profile.Editor && profile != Profile.Reviewer
            && profile != Profile.UserAdmin && profile != Profile.Administrator)
            throw new NoApplicableCodeEx("User not allowed to insert metadata.");

        int userId = us.getUserIdAsInt();

        AccessManager am = gc.getBean(AccessManager.class);
View Full Code Here

    private int updateTransaction(Element request, Element xml, ServiceContext context, Set<String> toIndex) throws Exception {
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        DataManager dataMan = gc.getBean(DataManager.class);

        if (context.getUserSession().getUserId() == null) {
            throw new NoApplicableCodeEx("User not authenticated.");
        }

        int totalUpdated = 0;


        // Update full metadata
        if (xml != null) {

            // Retrieve schema and the related Namespaces
            String schemaId = gc.getBean(SchemaManager.class).autodetectSchema(xml);

            if (schemaId == null) {
                throw new NoApplicableCodeEx("Can't identify metadata schema");
            }

            // Retrieve the metadata identifier

            String uuid = gc.getBean(DataManager.class).extractUUID(schemaId, xml);

            if (uuid.length() == 0) {
                throw new NoApplicableCodeEx("Metadata identifier not provided");
            }

            // Update metadata record
            String id = dataMan.getMetadataId(uuid);

            if (id == null) {
                return totalUpdated;
            }

            if (!gc.getBean(AccessManager.class).canEdit(context, id)) {
                throw new NoApplicableCodeEx("User not allowed to update this metadata(" + id + ").");
            }

            String changeDate = null;

            boolean validate = false;
            boolean ufo = false;
            boolean index = false;
            String language = context.getLanguage();
            dataMan.updateMetadata(context, id, xml, validate, ufo, index, language, changeDate, false);

            toIndex.add(id);

            totalUpdated++;

            return totalUpdated;

            // Update properties
        } else {
            //first, search the record in the database to get the record id
            final List<Element> constraints = request.getChildren("Constraint", Csw.NAMESPACE_CSW);
            Assert.isTrue(constraints.size() == 1, "One and only 1 constraint allowed in update query.  Found : " + constraints.size());
            Element constr = (Element) constraints.get(0).clone();
            List<Element> results = getResultsFromConstraints(context, constr);


            @SuppressWarnings("unchecked")
            List<Element> recordProperties = request.getChildren("RecordProperty", Csw.NAMESPACE_CSW);


            Iterator<Element> it = results.iterator();
            if (!it.hasNext())
                return totalUpdated;

            Set<String> updatedMd = new HashSet<String>();
            // Process all records selected
            while (it.hasNext()) {
                Element result = it.next();
                String uuid = result.getChildText("identifier", Csw.NAMESPACE_DC);
                String id = dataMan.getMetadataId(uuid);
                String changeDate = null;

                if (id == null)
                    continue;

                if (!dataMan.getAccessManager().canEdit(context, id))
                    throw new NoApplicableCodeEx("User not allowed to update this metadata(" + id + ").");


                Element metadata = dataMan.getMetadata(context, id, false, false, true);
                metadata.removeChild("info", Edit.NAMESPACE);

                // Retrieve the schema and Namespaces of metadata to update
                String schemaId = gc.getBean(DataManager.class).autodetectSchema(metadata);

                if (schemaId == null) {
                    throw new NoApplicableCodeEx("Can't identify metadata schema");
                }

                boolean metadataChanged = false;
                EditLib editLib = new EditLib(_schemaManager);
View Full Code Here

        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        DataManager dataMan = gc.getBean(DataManager.class);

        if (context.getUserSession().getUserId() == null)
            throw new NoApplicableCodeEx("User not authenticated.");

        //first, search the record in the database to get the record id
        Element constr = request.getChild("Constraint", Csw.NAMESPACE_CSW);
        List<Element> results = getResultsFromConstraints(context, constr);

        //second, delete the metadata in the dbms using the id
        Iterator<Element> i = results.iterator();
        if (!i.hasNext())
            return deleted;

        // delete all matching records
        while (i.hasNext()) {
            Element result = i.next();
            String uuid = result.getChildText("identifier", Csw.NAMESPACE_DC);
            String id = dataMan.getMetadataId(uuid);

            if (id == null) {
                return deleted;
            }

            if (!dataMan.getAccessManager().canEdit(context, id)) {
                throw new NoApplicableCodeEx("User not allowed to delete metadata : " + id);
            }

            dataMan.deleteMetadata(context, id);
            deleted++;
        }
View Full Code Here

                final int maxNumberOfRecordsForPropertyNames = _catalogConfig.getMaxNumberOfRecordsForPropertyNames();
                domainValues = handlePropertyName(_catalogConfig, propertyNames, context, false, maxNumberOfRecordsForPropertyNames,
                        cswServiceSpecificConstraint, _luceneConfig);
            } catch (Exception e) {
              Log.error(Geonet.CSW, "Error getting domain value for specified PropertyName : " + e);
              throw new NoApplicableCodeEx(
                      "Raised exception while getting domain value for specified PropertyName  : " + e);
          }
      response.addContent(domainValues);
      return response;
    }
View Full Code Here

TOP

Related Classes of org.fao.geonet.csw.common.exceptions.NoApplicableCodeEx

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.