Package pt.webdetails.cpf.repository.api

Examples of pt.webdetails.cpf.repository.api.IReadAccess


    }
    return null;
  }

  public static IReadAccess getSystemOrUserReadAccess( String filePath ) {
    IReadAccess readAccess = null;
    if ( filePath.startsWith( "/" + CdeEnvironment.getSystemDir() + "/" ) && ( filePath.endsWith( ".wcdf" ) || filePath
      .endsWith( ".cdfde" ) ) ) {
      readAccess = getSystemReadAccess( filePath.split( "/" )[ 2 ], null );
    } else if ( CdeEnvironment.getUserContentAccess().hasAccess( filePath, FileAccess.EXECUTE ) ) {
      readAccess = CdeEnvironment.getUserContentAccess();
View Full Code Here


  public String[] getWidgetParameters() {
    return this._widgetParameters.toArray( new String[ 0 ] );
  }

  public static DashboardWcdfDescriptor load( String wcdfFilePath ) throws IOException {
    IReadAccess readAccess = Utils.getSystemOrUserReadAccess( wcdfFilePath );
    if ( readAccess == null || !readAccess.fileExists( wcdfFilePath ) ) {
      return null;
    }

    Document wcdfDoc = null;
    try {
      wcdfDoc = Utils.getDocFromFile( readAccess.fetchFile( wcdfFilePath ), null );
      DashboardWcdfDescriptor wcdf = DashboardWcdfDescriptor.fromXml( wcdfDoc );
      wcdf.setPath( wcdfFilePath );
      return wcdf;
    } catch ( DocumentException e ) {
      _logger.error( "DashboardWcdfDescriptor.load(wcdfFilePath)", e );
View Full Code Here

  private void readCustomComponentsLocation( MetaModel.Builder model, XmlFsPluginThingReaderFactory factory,
      PathOrigin origin ) throws ThingReadException {
    logger.info( "reading custom components from " + origin );

    GenericBasicFileFilter filter = new GenericBasicFileFilter( COMPONENT_FILENAME, DEFINITION_FILE_EXT );
    IReadAccess access = origin.getReader( contentAccessFactory );
    List<IBasicFile> filesList = access.listFiles( null, filter, IReadAccess.DEPTH_ALL, false, true );

    if ( filesList != null ) {
      logger.debug( String.format( "%d sub-folders found", filesList.size() ) );

      IBasicFile[] filesArray = filesList.toArray( new IBasicFile[] { } );
View Full Code Here

  }

  protected IBasicFile getTargetDashboardBaseMessageFile() {
    if ( targetDashboardBaseMsgFile == null ) {

      IReadAccess systemReader =
          CdeEnvironment.getPluginSystemReader( Utils.joinPath( BASE_CACHE_DIR, msgsRelativeDir ) );

      String msg =
          sourceDashboardBaseMsgFile != null ? sourceDashboardBaseMsgFile.getName() : BASE_GLOBAL_MESSAGE_SET_FILENAME
              + ".properties";

      if ( systemReader.fileExists( msg ) ) {
        targetDashboardBaseMsgFile = systemReader.fetchFile( msg );
      }
    }
    return targetDashboardBaseMsgFile;

  }
View Full Code Here

      }
    } else {
      _logger.info( "Bypassing Dashboard instance cache, reading from repository." );
    }

    IReadAccess userAccess = Utils.getSystemOrUserReadAccess( cdeFilePath );
    // Read cache, cache item existed and it is valid?
    if ( cachedDash != null
      && cachedDash.getSourceDate().getTime() >= userAccess.getLastModified( cdeFilePath ) ) {
      // Check WCDF file date as well

      if ( !userAccess.fileExists( wcdf.getPath() ) ) {
        throw new ThingReadException( new FileNotFoundException( wcdf.getPath() ) );
      }

      if ( cachedDash.getSourceDate().getTime() >= userAccess.getLastModified( wcdf.getPath() ) ) {
        _logger.debug( "Cached Dashboard instance is valid, using it." );

        return cachedDash;
      }
    }
View Full Code Here

  }

  private CdfRunJsDashboardWriteResult
  getDashboardWriteResultFromCache( DashboardCacheKey cacheKey, String cdeFilePath ) throws FileNotFoundException {

    IReadAccess userContentAccess = Utils.getSystemOrUserReadAccess( cdeFilePath );

    // 1. Try to obtain dashboard from cache
    Element cacheElement;
    try {
      synchronized ( this._ehCacheLock ) {
        cacheElement = this._ehCache.get( cacheKey );
      }
    } catch ( CacheException ex ) {
      _logger.info( "Cached dashboard render invalidated, re-rendering." );
      return null;
    }

    // 2. In the cache?
    if ( cacheElement == null ) {
      _logger.debug( "Dashboard render is not in cache." );
      return null;
    }

    CdfRunJsDashboardWriteResult dashWrite = (CdfRunJsDashboardWriteResult) cacheElement.getValue();

    // 3. Get the template file
    String templPath = cacheKey.getTemplate();

    // 4. Check if cache item has expired
    // Cache is invalidated if the dashboard or template have changed since
    // the cache was loaded, or at midnight every day,
    // because of dynamic generation of date parameters.
    Calendar cal = Calendar.getInstance();
    cal.set( Calendar.HOUR_OF_DAY, 00 );
    cal.set( Calendar.MINUTE, 00 );
    cal.set( Calendar.SECOND, 1 );

    // The date at which the source Dashboard object
    // was loaded from disk, not the date at which the DashResult was written.
    Date dashLoadedDate = dashWrite.getLoadedDate();

    boolean cacheExpired = cal.getTime().after( dashLoadedDate );
    if ( cacheExpired ) {
      _logger.debug( "Cached dashboard render expired, re-rendering." );
      return null;
    }

    boolean cacheInvalid =
      ( userContentAccess.getLastModified( cdeFilePath ) > dashLoadedDate.getTime() )
        || ( userContentAccess.fileExists( templPath )
        && userContentAccess.getLastModified( templPath ) > dashLoadedDate.getTime() );
    if ( cacheInvalid ) {
      _logger.info( "Cached dashboard render invalidated, re-rendering." );
      return null;
    }
View Full Code Here

  }

  protected IBasicFile getGlobalMsgCacheFile() {
    if ( globalMsgCacheFile == null ) {

      IReadAccess systemReader =
          CdeEnvironment.getPluginSystemReader( Utils.joinPath( BASE_CACHE_DIR, msgsRelativeDir ) );

      String msg = BASE_GLOBAL_MESSAGE_SET_FILENAME + ".properties";

      if ( systemReader.fileExists( msg ) ) {
        globalMsgCacheFile = systemReader.fetchFile( msg );
      }
    }

    return globalMsgCacheFile;
  }
View Full Code Here

      if ( StringUtils.isEmpty( cdeFilePath ) ) {
        cdeFileInput =
          CdeEnvironment.getPluginSystemReader().getFileInputStream( SYSTEM_PLUGIN_EMPTY_STRUCTURE_FILE_PATH );
        wcdfFilePath = SYSTEM_PLUGIN_EMPTY_WCDF_FILE_PATH;
      } else {
        IReadAccess access = Utils.getSystemOrUserReadAccess( cdeFilePath );
        if ( access.fileExists( cdeFilePath ) ) {
          cdeFileInput = access.getFileInputStream( cdeFilePath );
          wcdfFilePath = cdeFilePath.replace( ".cdfde", ".wcdf" );
        } else {
          String msg = "File not found " + cdeFilePath + " in " + access;
          logger.error( msg );
          return JsonUtils.getJsonResult( false, msg );
View Full Code Here

    // special case for widgets: copy widget samples into dir if creating dir for the first time
    if ( !repoBase.fileExists( CdeConstants.SolutionFolders.WIDGETS ) ) {
      if ( !ensureDirExists( repoBase, CdeConstants.SolutionFolders.WIDGETS ) ) {
        logger.error( "Couldn't find or create CDE widgets dir." );
      } else {
        IReadAccess sysPluginSamples = CdeEnvironment.getPluginSystemReader( "resources/samples/" );
        saveAndClose( repoBase, Util.joinPath( CdeConstants.SolutionFolders.WIDGETS, "sample.cdfde" ),
          sysPluginSamples, "widget.cdfde" );
        saveAndClose( repoBase, Util.joinPath( CdeConstants.SolutionFolders.WIDGETS, "sample.wcdf" ), sysPluginSamples,
          "widget.wcdf" );
        saveAndClose( repoBase, Util.joinPath( CdeConstants.SolutionFolders.WIDGETS, "sample.cda" ), sysPluginSamples,
View Full Code Here

  public static String getEditor( String wcdfPath, boolean debugMode, String scheme, boolean isDefault )
    throws Exception {

    ResourceManager resMgr = ResourceManager.getInstance();
    IReadAccess sysReader = CdeEnvironment.getPluginSystemReader();

    final HashMap<String, String> tokens = buildReplacementTokenMap( wcdfPath, scheme, debugMode, resMgr, sysReader );

    return getProcessedEditor( wcdfPath, resMgr, tokens, sysReader, isDefault );
View Full Code Here

TOP

Related Classes of pt.webdetails.cpf.repository.api.IReadAccess

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.