// Path: cfr-pentaho-base/src/pt/webdetails/cfr/CfrEnvironment.java
// public class CfrEnvironment extends PentahoPluginEnvironment implements ICfrEnvironment {
// 
//   private static final String PLUGIN_NAME = "cfr";
//   private static final String PROPERTIES_FILE = "cfr.properties";
//   private static boolean persistenceEngineInitialized = false;
// 
//   private IBeanFactory factory;
//   private IFileRepository repository;
//   private static Properties config;
// 
//   static Log logger = LogFactory.getLog( CfrEnvironment.class );
// 
//   public void init( IBeanFactory factory ) {
//     this.factory = factory;
// 
//     if ( factory.containsBean( IFileRepository.class.getSimpleName() ) ) {
//       repository = (IFileRepository) factory.getBean( IFileRepository.class.getSimpleName() );
//     }
// 
//     super.init( this );
//   }
// 
//   public static Properties getConfig() {
//     if ( config == null ) {
//       IReadAccess sysReader = getInstance().getPluginSystemReader( "" );
//       if ( sysReader.fileExists( PROPERTIES_FILE ) ) {
//         config = new Properties();
//         try {
//           config.load( sysReader.getFileInputStream( PROPERTIES_FILE ) );
//           logger.debug( PROPERTIES_FILE + " read ok." );
//         } catch ( IOException e ) {
//           logger.error( "Error reading " + PROPERTIES_FILE, e );
//         }
//       } else {
//         logger.error( "Unable to load " + PROPERTIES_FILE );
//       }
//     }
//     return config;
//   }
// 
//   public CfrEnvironment() {
//     init( new AbstractBeanFactory(){
//       @Override
//       public String getSpringXMLFilename(){ return "cfr.spring.xml"; }
//     });
//   }
// 
//   @Override public IPluginUtils getPluginUtils() {
//     return null;
//   }
// 
//   @Override public String getPluginName() {
//     return PLUGIN_NAME;
//   }
// 
//   @Override public ISessionUtils getSessionUtils() {
//     return null;
//   }
// 
//   @Override public void reload() {
// 
//   }
// 
//   public IFileRepository getRepository() {
//     return repository;
//   }
// 
//   public static PersistenceEngine getPersistenceEngine() {
// 
//     PersistenceEngine engine = PersistenceEngine.getInstance();
//     if ( !persistenceEngineInitialized ) {
//       synchronized ( CfrEnvironment.class ) {
//         if ( !persistenceEngineInitialized ) {
//           if ( !engine.classExists( FileStorer.FILE_METADATA_STORE_CLASS ) ) {
//             engine.initializeClass( FileStorer.FILE_METADATA_STORE_CLASS );
//           }
//           if ( !engine.classExists( FileStorer.FILE_PERMISSIONS_METADATA_STORE_CLASS ) ) {
//             engine.initializeClass( FileStorer.FILE_PERMISSIONS_METADATA_STORE_CLASS );
//           }
//           persistenceEngineInitialized = true;
//         }
// 
//       }
//     }
// 
//     return engine;
//   }
// 
// 
// }
// 
// Path: cfr-pentaho5/src/pt/webdetails/cfr/CfrService.java
// public class CfrService {
// 
//   protected static final Log logger = LogFactory.getLog( CfrService.class );
// 
//   public IFileRepository getRepository() {
//     return new CfrEnvironment().getRepository();
//   }
// 
//   public String getCurrentUserName() {
//     IPentahoSession session = PentahoSessionHolder.getSession();
//     return session.getName();
//   }
// 
//   public boolean isCurrentUserAdmin() {
//     return SecurityHelper.getInstance().isPentahoAdministrator( PentahoSessionHolder.getSession() );
//   }
// 
//   public List<String> getUserRoles() {
//     PentahoSession sessionInfo = new PentahoSession( PentahoSessionHolder.getSession() );
//     return Arrays.asList( sessionInfo.getAuthorities() );
//   }
// 
// }


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tika.Tika;
import org.json.JSONException;
import org.json.JSONObject;
import pt.webdetails.cfr.CfrEnvironment;
import pt.webdetails.cfr.CfrService;
import pt.webdetails.cfr.auth.FilePermissionMetadata;
import pt.webdetails.cfr.repository.IFileRepository;
import pt.webdetails.cpf.persistence.PersistenceEngine;
import com.orientechnologies.orient.core.record.impl.ODocument;
import pt.webdetails.cpf.utils.MimeTypes;
/*!
* Copyright 2002 - 2015 Webdetails, a Pentaho company. All rights reserved.
*
* This software was developed by Webdetails and is provided under the terms
* of the Mozilla Public License, Version 2.0, or any later version. You may not use
* this file except in compliance with the license. If you need a copy of the license,
* please go to http://mozilla.org/MPL/2.0/. The Initial Developer is Webdetails.
*
* Software distributed under the Mozilla Public License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
* the license for the specific language governing your rights and limitations.
*/

package pt.webdetails.cfr.file;






public class FileStorer {

  public static final String FILE_METADATA_STORE_CLASS = "UploadedFiles";

// Path: cfr-pentaho-base/src/pt/webdetails/cfr/CfrEnvironment.java
// public class CfrEnvironment extends PentahoPluginEnvironment implements ICfrEnvironment {
// 
//   private static final String PLUGIN_NAME = "cfr";
//   private static final String PROPERTIES_FILE = "cfr.properties";
//   private static boolean persistenceEngineInitialized = false;
// 
//   private IBeanFactory factory;
//   private IFileRepository repository;
//   private static Properties config;
// 
//   static Log logger = LogFactory.getLog( CfrEnvironment.class );
// 
//   public void init( IBeanFactory factory ) {
//     this.factory = factory;
// 
//     if ( factory.containsBean( IFileRepository.class.getSimpleName() ) ) {
//       repository = (IFileRepository) factory.getBean( IFileRepository.class.getSimpleName() );
//     }
// 
//     super.init( this );
//   }
// 
//   public static Properties getConfig() {
//     if ( config == null ) {
//       IReadAccess sysReader = getInstance().getPluginSystemReader( "" );
//       if ( sysReader.fileExists( PROPERTIES_FILE ) ) {
//         config = new Properties();
//         try {
//           config.load( sysReader.getFileInputStream( PROPERTIES_FILE ) );
//           logger.debug( PROPERTIES_FILE + " read ok." );
//         } catch ( IOException e ) {
//           logger.error( "Error reading " + PROPERTIES_FILE, e );
//         }
//       } else {
//         logger.error( "Unable to load " + PROPERTIES_FILE );
//       }
//     }
//     return config;
//   }
// 
//   public CfrEnvironment() {
//     init( new AbstractBeanFactory(){
//       @Override
//       public String getSpringXMLFilename(){ return "cfr.spring.xml"; }
//     });
//   }
// 
//   @Override public IPluginUtils getPluginUtils() {
//     return null;
//   }
// 
//   @Override public String getPluginName() {
//     return PLUGIN_NAME;
//   }
// 
//   @Override public ISessionUtils getSessionUtils() {
//     return null;
//   }
// 
//   @Override public void reload() {
// 
//   }
// 
//   public IFileRepository getRepository() {
//     return repository;
//   }
// 
//   public static PersistenceEngine getPersistenceEngine() {
// 
//     PersistenceEngine engine = PersistenceEngine.getInstance();
//     if ( !persistenceEngineInitialized ) {
//       synchronized ( CfrEnvironment.class ) {
//         if ( !persistenceEngineInitialized ) {
//           if ( !engine.classExists( FileStorer.FILE_METADATA_STORE_CLASS ) ) {
//             engine.initializeClass( FileStorer.FILE_METADATA_STORE_CLASS );
//           }
//           if ( !engine.classExists( FileStorer.FILE_PERMISSIONS_METADATA_STORE_CLASS ) ) {
//             engine.initializeClass( FileStorer.FILE_PERMISSIONS_METADATA_STORE_CLASS );
//           }
//           persistenceEngineInitialized = true;
//         }
// 
//       }
//     }
// 
//     return engine;
//   }
// 
// 
// }
// 
// Path: cfr-pentaho5/src/pt/webdetails/cfr/CfrService.java
// public class CfrService {
// 
//   protected static final Log logger = LogFactory.getLog( CfrService.class );
// 
//   public IFileRepository getRepository() {
//     return new CfrEnvironment().getRepository();
//   }
// 
//   public String getCurrentUserName() {
//     IPentahoSession session = PentahoSessionHolder.getSession();
//     return session.getName();
//   }
// 
//   public boolean isCurrentUserAdmin() {
//     return SecurityHelper.getInstance().isPentahoAdministrator( PentahoSessionHolder.getSession() );
//   }
// 
//   public List<String> getUserRoles() {
//     PentahoSession sessionInfo = new PentahoSession( PentahoSessionHolder.getSession() );
//     return Arrays.asList( sessionInfo.getAuthorities() );
//   }
// 
// }


// Path: cfr-pentaho-base/src/pt/webdetails/cfr/file/FileStorer.java
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tika.Tika;
import org.json.JSONException;
import org.json.JSONObject;
import pt.webdetails.cfr.CfrEnvironment;
import pt.webdetails.cfr.CfrService;
import pt.webdetails.cfr.auth.FilePermissionMetadata;
import pt.webdetails.cfr.repository.IFileRepository;
import pt.webdetails.cpf.persistence.PersistenceEngine;
import com.orientechnologies.orient.core.record.impl.ODocument;
import pt.webdetails.cpf.utils.MimeTypes;

/*!
* Copyright 2002 - 2015 Webdetails, a Pentaho company. All rights reserved.
*
* This software was developed by Webdetails and is provided under the terms
* of the Mozilla Public License, Version 2.0, or any later version. You may not use
* this file except in compliance with the license. If you need a copy of the license,
* please go to http://mozilla.org/MPL/2.0/. The Initial Developer is Webdetails.
*
* Software distributed under the Mozilla Public License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
* the license for the specific language governing your rights and limitations.
*/

package pt.webdetails.cfr.file;






public class FileStorer {

  public static final String FILE_METADATA_STORE_CLASS = "UploadedFiles";

  public static final String FILE_PERMISSIONS_METADATA_STORE_CLASS = "UploadedFilesPermissions";