Skip to content
josegar74 edited this page Apr 10, 2014 · 5 revisions
Date Apr 4 2014 Contacts Jose García
Status In Progress Release 2.12
Resources Ticket # https://github.com/geonetwork/core-geonetwork/issues/436
Source code coming soon
Funding Ontario Ministry of Natural Resources (OMNR)

Overview

This feature allows administrators to create the following reports in CSV format:

  • Internal metadata records (metadata not published to group ALL).
  • Updated metadata records during a period of time.
  • File uploads to metadata records in a period of time.
  • File downloads to metadata records in a period of time.
  • Users access in a period of time.

New reports can be added in the system in the future.

Dashboard option

Updated metadata report

Technical Details:

User interface

A new AngularJS GnReportController handles the reports UI and invocation of Java services to create the CSV files.

To download the CSV as a file with Ajax POST is not that immediate/intuitive. When the Java service(s) that create the reports returns the responses, some "magic" is required to force the browser to download as a file. See success event in the following snippet:

     $scope.createReport = function (formId, service) {
        $http({
          method: 'POST',
          url: service,
          data: $(formId).serialize(),
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        })
          .success(function(data) {
            var element = angular.element('<a/>');
            element.attr({
              href: 'data:attachment/csv;charset=utf-8,' + encodeURI(data),
              target: '_blank',
              download: service
            })[0].click();

          })
      };

Users access

The User domain class has been enhanced to track the last login user date.

A new Spring ApplicationListener has been created to handle successful users login. The listener is configured in config-security-core.xml

  <!-- Listener to log the last login date in the database -->
  <bean class="org.fao.geonet.kernel.security.listener.UpdateTimestampListener" id="updateTimestampListener">

Metadata file uploads/downloads

Metadata file upload and download services have been extended to track this information to create the related reports:

  • User requesting the upload/download.
  • File uploaded/downloaded.
  • Date of upload/download.

This data is stored in the database in 2 new tables: metadatafileuploads and metadatafiledownloads.

When a file is removed or a metadata with files is removed, the upload/download related records are "removed" using a logical delete, setting the delete date field of the records. This allows to keep historical information for the reports.

The upload/download reports include a column Expire Date with the file delete date to indicate that the file is not longer available.

Metadata file upload/download/remove service handlers

Metadata file upload/download/remove services have been extended to allow execute custom functionality. To implement this, default handler classes as Spring beans.

These default handlers classes manage to store/retrieve the file(s) from the GeoNetwork data directory and store also the upload/download request in the database for the reports.

Handlers configuration in Spring:

  <bean id="resourceUploadHandler" class="org.fao.geonet.services.resources.handler.DefaultResourceUploadHandler" />

  <bean id="resourceDownloadHandler" class="org.fao.geonet.services.resources.handler.DefaultResourceDownloadHandler" />

  <bean id="resourceRemoveHandler" class="org.fao.geonet.services.resources.handler.DefaultResourceRemoveHandler" />

Interface to implement for IResourceUploadHandler:

public interface IResourceUploadHandler {
    /**
     *
     * @param context
     * @param params
     * @param metadataId
     * @throws ResourceHandlerException
     */
    public void onUpload(ServiceContext context, Element params, int metadataId,
                         String fileName, double fileSize) throws ResourceHandlerException;
}

Default upload handler:

public class DefaultResourceUploadHandler implements IResourceUploadHandler {

    public void onUpload(ServiceContext context, Element params,
                         int metadataId, String fileName, double fileSize) throws ResourceHandlerException {
        
        try {
            String uploadDir = context.getUploadDir();
            String access = Util.getParam(params, Params.ACCESS, "private");
            String overwrite = Util.getParam(params, Params.OVERWRITE, "no");

            File dir = new File(Lib.resource.getDir(context, access, metadataId));
            moveFile(context, uploadDir, fileName, dir, overwrite);

            storeFileUploadRequest(context, metadataId, fileName, fileSize);

        } catch (Exception ex) {
            ex.printStackTrace();
            throw new ResourceHandlerException(ex);
        }
    }

Usage of the upload handler in the service org.fao.geonet.services.resources.Upload:

  IResourceUploadHandler uploadHook = (IResourceUploadHandler) context.getApplicationContext().getBean("resourceUploadHandler");
        uploadHook.onUpload(context, params, Integer.parseInt(id), fname, new Double(fsize).doubleValue());

This should allow to customise the metadata files storage and retrieval, implementing new handlers without changing the services.

An example of usage of these handlers is for Ontario Ministry of Natural Resources (OMNR), implementing custom handlers to user FME server for file storage.

Reports

Some examples of reports output.

Users access report

User name,Last name,First name,Email,Groups/User Roles,Last Login Date,
admin,Doe,John,[email protected],,2014-04-10T09:54:57,
jose,García,Jose,[email protected],Sample group/Editor-Sample group/Reviewer,2014-04-10T08:48:49,

File uploads report

Uploader (Username),Uploader (Last name),Uploader (First name),Uploader (Email),Uploader (Role),Metadata uuid,Record Name,File Name,Product Name,Upload Date,Expiry Date,
admin,Doe,John,[email protected],Administrator,5e05356d-db78-42a8-9d7f-ff49024fc045,Test metadata,data.doc,Document,2014-04-10T12:26:59,2014-04-10T12:51:25,
admin,Doe,John,[email protected],Administrator,5e05356d-db78-42a8-9d7f-ff49024fc045,Test metadata,image.png,Graphic,2014-04-10T12:27:23,,

Proposal Type:

  • Type: Admin-UI
  • Module: web-ui,domain,services,core

Voting History

  • Vote Proposed: TBA

Participants

  • All
Clone this wiki locally