text:
Distributed Machile Learning System for intron-exon predictioin in human DNA.

## How to run
Application depends on 2 data files (see below in `Data` section).
- `sbt run`

## How to test
- `sbt test`

## Data

Application depends on 2 data files located in the `./data/` folder.
- `exons.txt`
- `genes.txt`

See below how can you obtain them.

### Dummy Test Data
- `/src/test/resources/data/exons.sample`
- `/src/test/resources/data/genes.sample`

### Data Download
You can download and decompress data files:
- human genome exons [exons.txt](https://drive.google.com/file/d/0BzlYsyqnvqi3MllabFYzckVCdmc/view?usp=sharing)
- human genome genes [genes.txt](https://drive.google.com/file/d/0BzlYsyqnvqi3SVpTNmEydTYyaDQ/view?usp=sharing)

### Data Generation
You can generate data from eENSEMBL files yourself:

#### Generating `exons.txt` file

1. Navigate to http://www.ensembl.org/biomart/martview/
2. In `- CHOOSE DATABASE -` select `Ensembl Genes 86`
3. In `- CHOOSE DATASET - ` select `Homo sapiens genes (GRCh38.p7)`
4. Click `Attributes`
5. Select `Sequences`
6. Expand  `Heder Informations` end select the following attributes, and unselect all the rest:
  1. Ensembl Gene ID
  2. Ensembl Exon ID
7. Expand  `Sequences` and select `Exon sequences`, so that the left panel of attributes looks like (preserving the order):
  - Gene ID
  - Exon ID
  - Exon sequences
8. Click `Results`
9. Select `Compressed file (.gz)`
10. Click `Go`
11. Rename the downloaded file to `exons.txt`

#### Generating `genes.txt` file

1. Navigate to http://www.ensembl.org/biomart/martview/
2. In `- CHOOSE DATABASE -` select `Ensembl Genes 86`
3. In `- CHOOSE DATASET - ` select `Homo sapiens genes (GRCh38.p7)`
4. Click `Attributes`
5. Select `Sequences`
6. Expand  `Heder Informations` end select the following attributes, and unselect all the rest:
  1. Ensembl Gene ID
  2. Ensembl Exon ID
7. Expand  `Sequences` and select `Unspliced (Gene)`, so that the left panel of attributes looks like (preserving the order):
  - Gene ID
  - Exon ID
  - Unspliced (Gene)
9. Click `Filters` on the left panel
10. Expand `Region`
11. Check `Chromosome/scaffold`
12. Select `1` from the multi-select list
13. Click `Results`
14. Select `Compressed file (.gz)`
15. Click `Go`
16. Rename the downloaded file to `genes-1.txt`
17. Perform the above steps for chromosomes `1` to `22` as well as for `X` and `Y` chromosomes
18. Concatenate 24 resulting files into a single `genes.txt` file


text:
package ccv3

import (
	"io"
	"net/http"

	"code.cloudfoundry.org/cli/api/cloudcontroller"
	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
)

// requestOptions contains all the options to create an HTTP request.
type requestOptions struct {
	// URIParams are the list URI route parameters
	URIParams internal.Params

	// Query is a list of HTTP query parameters. Query will overwrite any
	// existing query string in the URI. If you want to preserve the query
	// string in URI make sure Query is nil.
	Query []Query

	// RequestName is the name of the request (see routes)
	RequestName string

	// Method is the HTTP method.
	Method string
	// URL is the request path.
	URL string
	// Body is the content of the request.
	Body io.ReadSeeker
}

// newHTTPRequest returns a constructed HTTP.Request with some defaults.
// Defaults are applied when Request options are not filled in.
func (client *Client) newHTTPRequest(passedRequest requestOptions) (*cloudcontroller.Request, error) {
	var request *http.Request
	var err error

	if passedRequest.URL != "" {
		request, err = http.NewRequest(
			passedRequest.Method,
			passedRequest.URL,
			passedRequest.Body,
		)
	} else {
		request, err = client.router.CreateRequest(
			passedRequest.RequestName,
			map[string]string(passedRequest.URIParams),
			passedRequest.Body,
		)
	}
	if err != nil {
		return nil, err
	}

	if passedRequest.Query != nil {
		request.URL.RawQuery = FormatQueryParameters(passedRequest.Query).Encode()
	}

	request.Header = http.Header{}
	request.Header.Set("Accept", "application/json")
	request.Header.Set("User-Agent", client.userAgent)

	if passedRequest.Body != nil {
		request.Header.Set("Content-Type", "application/json")
	}

	return cloudcontroller.NewRequest(request, passedRequest.Body), nil
}

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE html>

	<title>Fittable Description</title>

	<meta name="viewport" content="width=device-width, initial-scale=1.0">


text:
'use babel';

import NcGcodeView from './nc-gcode-view';
import { CompositeDisposable } from 'atom';

export default {

  ncGcodeView: null,
  modalPanel: null,
  subscriptions: null,

  activate(state) {
    this.ncGcodeView = new NcGcodeView(state.ncGcodeViewState);
    this.modalPanel = atom.workspace.addModalPanel({
      item: this.ncGcodeView.getElement(),
      visible: false
    });

    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
    this.subscriptions = new CompositeDisposable();

    // Register command that toggles this view
    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'nc-gcode:toggle': () => this.toggle()
    }));
  },

  deactivate() {
    this.modalPanel.destroy();
    this.subscriptions.dispose();
    this.ncGcodeView.destroy();
  },

  serialize() {
    return {
      ncGcodeViewState: this.ncGcodeView.serialize()
    };
  },

  toggle() {
    console.log('NcGcode was toggled!');
    return (
      this.modalPanel.isVisible() ?
      this.modalPanel.hide() :
      this.modalPanel.show()
    );
  }

};


text:
/*
 * base stylesheets included in every chart
 */
.chart #header {
  min-height: 1px;
  position: relative;
}
.chart #header .header-right {
  position: absolute;
  right: 10px;
  z-index: 20;
}
.chart #footer {
  min-height: 1px;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 25px;
}
.chart #footer .footer-left,
.chart #footer .footer-right {
  position: absolute;
  bottom: 5px;
  z-index: 1000;
}
.chart #footer .footer-left {
  left: 5px;
}
.chart #footer .footer-right {
  right: 5px;
}
.chart .logo {
  position: absolute;
  right: 0;
  bottom: 0;
}
.chart .logo .big {
  display: none;
}
.chart.plain #footer {
  height: 10px;
}
.chart.js .noscript {
  display: none;
}
.chart .hidden {
  display: none;
}
.chart .label.annotation span {
  background: transparent;
}
.chart .dw-chart-notes {
  font-size: 11px;
  color: #888;
  margin-bottom: 1em;
}

.chart.vis-stacked-column-chart {
    overflow: hidden;
}

.chart.vis-grouped-column-chart {
    overflow: hidden;
}

/*
 * Default Theme
 * -------------
 *
 */

body, html {

}

a { color: #0088CC; }

body.chart {
    font-family: Helvetica Neue, Arial;
    font-weight: 400;
    font-size: 12px;
    margin: 0 0px;
    background: #fff;
}

h1 {
    font-size: 22px;
    font-weight: 300;
    margin: 0 0 10px;
    text-align: left;
}

h1 span {
}

/* NOTE: On IE, there is a border around each image which is a link */
a img { border:0px; }

.chart p { margin: 5px 0 10px!important; line-height: 17px;}

#chart {
    margin-top: 10px;
}

.label {
    font-size: 12px;
}

.label span {
    color: #333;
    text-shadow: 0 0 2px #fff;
}

.label.inverted span {
    text-shadow: 0 0px 2px #000000;
}

.label.outline span {
    text-shadow: 0 1px 0 #FFFFFF, 1px 0 0 #FFFFFF, 0 -1px 0 #FFFFFF, -1px 0 0 #FFFFFF,
        1px 1px 0 #FFFFFF, 1px -1px 0 #FFFFFF, -1px -1px 0 #FFFFFF, -1px 1px 0 #FFFFFF,
        0 2px 1px #FFFFFF, 2px 0 1px #FFFFFF, 0 -2px 1px #FFFFFF, -2px 0 1px #FFFFFF,
        -1px 2px 0px #FFFFFF, 2px -1px 0px #FFFFFF, -1px -2px 0px #FFFFFF, -2px -1px 0px #FFFFFF,
        1px 2px 0px #FFFFFF, 2px 1px 0px #FFFFFF, 1px -2px 0px #FFFFFF, -2px 1px 0px #FFFFFF;
}

.label.outline span sup {
    text-shadow: none;
}

.label.highlighted, .label.axis {
    font-size: 12px;
    z-index: 100;
}

.label.hover {
    font-weight: bold;
}

.label.inverted span {
    color: #fff;
}

.label.highlighted {
    font-weight: bold;
}

.label.value span {
    font-size: 12px;
}

.label.series span {
    font-size: 12px;
}

.tooltip {
    z-index: 200;
    padding-bottom: 0px;
}

.tooltip .content {
    background-color: #fff;
    border: 1px solid #888;
    box-shadow: 2px 2px 2px rgba(0,0,0,.2);
    padding: 5px 8px;
}

.tooltip label {
    font-weight: 700;
}

.tooltip label:after {
    content: ": ";
}

.dw-chart-notes {
    font-style: italic;
    margin-bottom: 10px;
}

.chart.theme-default .dw-chart-notes {
    font-style: italic;
    margin-bottom: 5px;
    position: relative;
    margin-top: 10px;
}

#footer {
    font-size: 11px;
    color: #888;
    /* The footer must now cover the chart to allow
    the toggleable panel to "go up" */
    z-index: 1100;
    /* Sets the background here to propagate it to its children */
    background:transparent;
}

.chart.theme-default #footer .footer-left {
    left: 0;
}

#footer .footer-left {
    bottom:0;
    /* Vertical text align */
}

/* We have to break to absolute positionof the footer
to allow absolute positioning related to the #footer
within the .toggleable-panel */
#footer .footer-right {
    position: absolute;
    bottom: 0;
    right: 0;
}

/* Target screens under 400px */
@media all and (max-width: 400px) {
    /* We must compensate the right offset
    that we just removed by adding this distances to
    the .toggle-panel element (that toggles the about panel).
    We choose to user padding to enlarge the touchable area.  */

    .chart #footer { height: auto; }

    .chart #footer .footer-left {
        position: static;
    }

    .chart #footer .footer-right {
        position:static;
        float:none;
        text-align:left;
        /* Vertical text align */
        padding: 0;
        margin: 2px 0 0;
    }
}

.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

.clearfix {
    display: inline-block;
}

html[xmlns] .clearfix {
    display: block;
}

* html .clearfix {
    height: 1%;
}

svg .axis, svg .tick, svg .grid, svg rect {
    shape-rendering: crispEdges;
}

.label.rotate90 {
    -moz-transform: rotate(-90deg);
    -webkit-transform: rotate(-90deg);
    -ms-transform: rotate(-90deg);
    -o-transform: rotate(-90deg);
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}

.label.smaller span {
    font-size: 80%;
}

.filter-links {
    height: 30px;
    overflow: hidden;
}

.filter-links a {
    padding: 0px 10px;
    box-shadow: 0 0 10px #ddd inset;
    border: 1px solid #bbb;
    border-left: 0;
    display: block;
    float: left;
    text-decoration: underline;
    color: #666;
    height: 28px;
    line-height: 28px;
    background: #fbfbfb;
}

.filter-links a:hover {
    background: #fff;
    color: #0088CC;
}

*+html .filter-links a {  background: #eeeeee; } /** IE7 hack **/
.filter-links a { background: #eeeeee\0/; }  /** IE8 hack **/

.filter-links a.active {
    font-weight: bold;
    color: #000;
    box-shadow: none;
    background: #fff;
    cursor: default;
    text-decoration: none;
}

.filter-links a:first-child {
    border-radius: 10px 0 0 10px;
    border-left: 1px solid #bbb;
}

.filter-links a:last-child {
    border-radius: 0 10px 10px 0;
}

.filter-select {
    background-color: #FFFFFF;
    border: 1px solid #CCCCCC;
    border-radius: 4px 4px 4px 4px;
    padding: 4px 6px;
    vertical-align: middle;
    font-size: 12px;
}

.line-chart .tooltip {
    border-radius: 5px;
}

/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
    /* no fullscreen button on smartphones, never */
    .fs-btn {
        display: none!important;
    }
}


text:
package gov.va.isaac.gui.refexViews.dynamicRefexListView;

import gov.va.isaac.AppContext;
import gov.va.isaac.gui.util.Images;
import gov.va.isaac.interfaces.gui.ApplicationMenus;
import gov.va.isaac.interfaces.gui.CheckMenuItemI;
import gov.va.isaac.interfaces.gui.MenuItemI;
import gov.va.isaac.interfaces.gui.constants.SharedServiceNames;
import gov.va.isaac.interfaces.gui.views.DockedViewI;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.layout.Region;
import javafx.stage.Window;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jvnet.hk2.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * {@link DynamicSememeListView}
 *
 * @author Dan Armbrust
 */
@Service @Named(value=SharedServiceNames.DOCKED)
@Singleton
public class DynamicSememeListView implements DockedViewI
{
	DynamicSememeListViewController drlvc_;
	private final Logger LOG = LoggerFactory.getLogger(this.getClass());

	private DynamicSememeListView()
	{
		// created by HK2
		LOG.debug(this.getClass().getSimpleName() + " construct time (blocking GUI): {}", 0);
	}

	/**
	 * @see gov.va.isaac.interfaces.gui.views.DockedViewI#getMenuBarMenuToShowView()
	 */
	@Override
	public CheckMenuItemI getMenuBarMenuToShowView()
	{
		CheckMenuItemI checkMenuItem = new CheckMenuItemI()
		{
			@Override
			public void handleMenuSelection(Window parent, MenuItem menuItem)
			{
				// noop
			}

			@Override
			public int getSortOrder()
			{
				return 20;
			}

			@Override
			public String getParentMenuId()
			{
				return ApplicationMenus.PANELS.getMenuId();
			}

			@Override
			public String getMenuName()
			{
				return "Dynamic Sememe View Panel";
			}

			@Override
			public String getMenuId()
			{
				return "dynamicSememeViewPanelMenuItem";
			}

			@Override
			public boolean enableMnemonicParsing()
			{
				return false;
			}

			/**
			 * @see gov.va.isaac.interfaces.gui.MenuItemI#getImage()
			 */
			@Override
			public Image getImage()
			{
				return Images.ATTACH.getImage();
			}
		};
		return checkMenuItem;
	}

	/**
	 * @see gov.va.isaac.interfaces.gui.views.DockedViewI#getViewTitle()
	 */
	@Override
	public String getViewTitle()
	{
		return "Sememe Viewer";
	}

	/**
	 * @see gov.va.isaac.interfaces.gui.views.ViewI#getView()
	 */
	@Override
	public Region getView()
	{
		if (drlvc_ == null)
		{
			try
			{
				drlvc_ = DynamicSememeListViewController.construct();
			}
			catch (IOException e)
			{
				LoggerFactory.getLogger(this.getClass()).error("Unexpected error initing DynamicSememeListView", e);
				AppContext.getCommonDialogs().showErrorDialog("Unexpected error creating DynamicSememeListView", e);
				return new Label("Unexpected error initializing view, see log file");
			}

		}
		return drlvc_.getRoot();
	}

	/**
	 * @see gov.va.isaac.interfaces.gui.views.IsaacViewI#getMenuBarMenus()
	 */
	@Override
	public List<MenuItemI> getMenuBarMenus()
	{
		// We don't currently have any custom menus with this view
		return new ArrayList<MenuItemI>();
	}

	@Override
	public void viewDiscarded()
	{
		//noop for now - this never gets called in the current GUI design for a docked view
	}
}


text:
#pragma once

#ifndef GEODE_THINCLIENTSTICKYMANAGER_H_
#define GEODE_THINCLIENTSTICKYMANAGER_H_

#include "TssConnectionWrapper.hpp"
#include <algorithm>
#include <vector>
#include <set>
#include <ace/Recursive_Thread_Mutex.h>
namespace apache {
namespace geode {
namespace client {
class ThinClientPoolDM;
class ServerLocation;
class TcrConnection;
class TcrEndpoint;
class ThinClientStickyManager {
 public:
  ThinClientStickyManager(ThinClientPoolDM* poolDM) : m_dm(poolDM) {}
  bool getStickyConnection(TcrConnection*& conn, GfErrType* error,
                           std::set<ServerLocation>& excludeServers,
                           bool forTransaction);
  void setStickyConnection(TcrConnection* conn, bool forTransaction);
  void addStickyConnection(TcrConnection* conn);
  void cleanStaleStickyConnection();

  void closeAllStickyConnections();
  bool canThisConnBeDeleted(TcrConnection* conn);

  void releaseThreadLocalConnection();
  void setSingleHopStickyConnection(TcrEndpoint* ep, TcrConnection*& conn);
  void getSingleHopStickyConnection(TcrEndpoint* ep, TcrConnection*& conn);
  void getAnyConnection(TcrConnection*& conn);

 private:
  static bool isNULL(TcrConnection** conn);
  ThinClientPoolDM* m_dm;
  std::set<TcrConnection**> m_stickyConnList;
  ACE_Recursive_Thread_Mutex m_stickyLock;
};
}  // namespace client
}  // namespace geode
}  // namespace apache

#endif  // GEODE_THINCLIENTSTICKYMANAGER_H_


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
Bull. Jard. bot. État Brux. 31: 74 (1961)

#### Original name
Ganoderma fassii var. dendroides Steyaert

### Remarks
null


text:
function add_isosurface2plot(xc,yc,zc,q,level,...
    isosurfvalues,isosurfcolors,isosurfalphas,mappedgrid)

% Internal Matlab routine used by Clawpack graphics

isurf = get_isosurfaces;

q = permute(q,[2 1 3]);

for n = 1:length(isosurfvalues),
  ivalue = isosurfvalues(n);
  icolor = isosurfcolors(n);
  ialpha = isosurfalphas(n);
  p = create_isosurface(xc,yc,zc,q,1,ivalue,icolor,ialpha,mappedgrid);
  isurf{n}{level}(end+1) = p;
end;

set_isosurfaces(isurf);


text:
ACCEPTED

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Annls mycol. 10(5): 450 (1912)

#### Original name
Chalara pteridina Syd. & P. Syd., 1912

### Remarks
null


text:
<?php defined('BX_DOL') or die('hack attempt');

/**
 * Menu representation.
 * @see BxDolMenu
 */
class BxBaseCmtsMenuActions extends BxTemplMenuCustom
{
    protected $_oCmts;
    protected $_aCmt;

    protected $_bShowTitles;

    public function __construct ($aObject, $oTemplate)
    {
        parent::__construct ($aObject, $oTemplate);

        $this->_bShowTitles = false;
    }

    public function setCmtsData($oCmts, $iCmtId)
    {
        if(empty($oCmts) || empty($iCmtId))
            return;

        $this->_oCmts = $oCmts;
        $this->_aCmt = $oCmts->getCommentRow($iCmtId);

        $sJsObject = $oCmts->getJsObjectName();
        $this->addMarkers(array(
            'js_object' => $sJsObject,
            'cmt_system' => $this->_oCmts->getSystemName(),
            'cmt_object_id' => $this->_oCmts->getId(),
            'cmt_id' => $iCmtId,
            'content_id' => $iCmtId,
            'reply_onclick' => $sJsObject . '.toggleReply(this, ' . $iCmtId . ')',
            'quote_onclick' => $sJsObject . '.toggleQuote(this, ' . $iCmtId . ')'
        ));
    }

    protected function _getMenuItemItemVote($aItem)
    {
        $oVote = $this->_oCmts->getVoteObject($this->_aCmt['cmt_unique_id']);
        if(!$oVote)
            return false;

        $aVotesParams = array('dynamic_mode' => $this->_bDynamicMode);
        if($this->_bShowTitles)
            $aVotesParams['show_do_vote_label'] = true;

        return $oVote->getElementInline($aVotesParams);
    }

    protected function _getMenuItemItemReaction($aItem)
    {
        $oReaction = $this->_oCmts->getReactionObject($this->_aCmt['cmt_unique_id']);
        if(!$oReaction)
            return false;

        $aReactionParams = array('dynamic_mode' => $this->_bDynamicMode);
        if($this->_bShowTitles)
            $aReactionParams['show_do_vote_label'] = true;

        return $oReaction->getElementInline($aReactionParams);
    }

    protected function _getMenuItemItemScore($aItem)
    {
        $oScore = $this->_oCmts->getScoreObject($this->_aCmt['cmt_unique_id']);
        if(!$oScore)
        	return false;

        $aScoresParams = array('dynamic_mode' => $this->_bDynamicMode);
        if($this->_bShowTitles)
		    $aScoresParams['show_do_vote_label'] = true;

    	return $oScore->getElementInline($aScoresParams);
    }

	protected function _getMenuItemItemReport($aItem)
    {
        $oReport = $this->_oCmts->getReportObject($this->_aCmt['cmt_unique_id']);
        if(!$oReport)
        	return false;

        $aReportParams = array('dynamic_mode' => $this->_bDynamicMode);
        if($this->_bShowTitles)
		    $aReportParams['show_do_report_label'] = true;

    	return $oReport->getElementInline($aReportParams);
    }

    /**
     * Check if menu items is visible.
     * @param $a menu item array
     * @return boolean
     */
    protected function _isVisible ($a)
    {
        if(!parent::_isVisible($a))
            return false;

        $sCheckFuncName = '';
        $aCheckFuncParams = array();
        switch ($a['name']) {
            case 'item-reply':
                $sCheckFuncName = 'isReplyAllowed';
                if(!empty($this->_aCmt))
                    $aCheckFuncParams = array($this->_aCmt);
                break;

            case 'item-quote':
                $sCheckFuncName = 'isQuoteAllowed';
                if(!empty($this->_aCmt))
                    $aCheckFuncParams = array($this->_aCmt);
                break;

            case 'item-vote':
                $sCheckFuncName = 'isVoteAllowed';
                if(!empty($this->_aCmt))
                    $aCheckFuncParams = array($this->_aCmt);
                break;

            case 'item-score':
                $sCheckFuncName = 'isScoreAllowed';
                if(!empty($this->_aCmt))
                    $aCheckFuncParams = array($this->_aCmt);
                break;

            case 'item-report':
                $sCheckFuncName = 'isReportAllowed';
                if(!empty($this->_aCmt))
                    $aCheckFuncParams = array($this->_aCmt);
                break;

            case 'item-edit':
                $sCheckFuncName = 'isEditAllowed';
                if(!empty($this->_aCmt))
                    $aCheckFuncParams = array($this->_aCmt);
                break;

            case 'item-delete':
                $sCheckFuncName = 'isRemoveAllowed';
                if(!empty($this->_aCmt))
                    $aCheckFuncParams = array($this->_aCmt);
                break;

            case 'item-more':
                $sCheckFuncName = 'isMoreAllowed';
                if(!empty($this->_aCmt))
                    $aCheckFuncParams = array($this->_aCmt);
                break;
        }

        if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
            return true;

        return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
    }
}

/** @} */


text:
class ClickMeter::Account < ClickMeter::Base
  #Get details of the current logged account
  # Response
  # {
  #     "email": "user@example.com",
  #     "firstName": "User",
  #     "registrationDate": "20150216140408",
  #     "timezone": 82,
  #     "timezonename": "Mountain Standard Time",
  #     "boGoVal": "LRQVtv9QYDvPbn41NZNvNA%3d%3d"
  # }

  get :take, "/account"

  #Update your account data
  # Response: empty string
  post :save, '/account'
end


text:
package es.weso.shex

import org.scalatest.FunSpec
import com.typesafe.config._
import com.hp.hpl.jena.rdf.model.ModelFactory
import java.io.FileOutputStream
import java.io.FileInputStream
import scala.collection.JavaConverters._
import org.scalatest.Matchers
import es.weso.shacl.Report

class RunTestsDeriv extends FunSpec with Matchers {
  val runner = RunTestsFolder(ShapeValidatorWithDeriv)
  val report = runner.createReport

  describe("test-suite report") {
    info("Running tests from " + runner.testsDir)
    info("Manifest file: " + runner.manifestFile)

    for ((r, n) <- report.items.sortWith(Report.sortReport) zip (1 to report.items.length))
      it(r.name + ". " + n) {
        if (!r.passed)
          fail("Test failed: " + r)
      }
  }

  describe("Generate W3c EARL report") {

    it("Should Generate EARL report ") {
      val earlModel = report.generateEARL
      val conf: Config = ConfigFactory.load()
      val outFile = conf.getString("EarlReportFile")

      earlModel.write(new FileOutputStream(outFile), "TURTLE")

      val readModel = ModelFactory.createDefaultModel()
      readModel.read(new FileInputStream(outFile), "", "TURTLE")
      val earl = "http://www.w3.org/ns/earl#"
      val earl_outcome = readModel.createProperty(earl + "outcome")
      val earl_passed = readModel.createResource(earl + "passed")
      val earl_failed = readModel.createResource(earl + "failed")
      val passed = readModel.listResourcesWithProperty(earl_outcome, earl_passed).toList.asScala
      val failed = readModel.listResourcesWithProperty(earl_outcome, earl_failed).toList.asScala
      info("Generated report " + passed.length + " passed. " + failed.length + " failed. File: " + outFile)
    }
  }

}


text:
<html>
<head>
<script>
    var referrerHeader = "<?php echo $_SERVER['HTTP_REFERER'] ?>";
    window.top.postMessage(referrerHeader, "*");
</script>
</head>
</html>


text:
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.testFramework;

import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.highlighting.HighlightUsagesHandler;
import com.intellij.ide.DataManager;
import com.intellij.injected.editor.DocumentWindow;
import com.intellij.injected.editor.EditorWindow;
import com.intellij.injected.editor.VirtualFileWindow;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.actionSystem.TypedAction;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.editor.impl.DocumentImpl;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.editor.impl.TrailingSpacesStripper;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.rt.execution.junit.FileComparisonFailure;
import com.intellij.util.ThrowableRunnable;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Before;
import org.junit.runners.Parameterized;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.*;

public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTestCase implements TestIndexingModeSupporter {
  private Editor myEditor;
  private PsiFile myFile;
  private VirtualFile myVFile;
  private TestIndexingModeSupporter.IndexingMode myIndexingMode = IndexingMode.SMART;

  @Override
  protected void runTestRunnable(@NotNull ThrowableRunnable<Throwable> testRunnable) throws Throwable {
    boolean runInWriteAction = false;

    if (isRunInCommand()) {
      Ref<Throwable> e = new Ref<>();
      CommandProcessor.getInstance().executeCommand(getProject(), () -> {
        try {
          super.runTestRunnable(testRunnable);
        }
        catch (Throwable throwable) {
          e.set(throwable);
        }
      }, null, null);
      if (!e.isNull()) {
        throw e.get();
      }
    }
    else {
      super.runTestRunnable(testRunnable);
    }
  }

  protected boolean isRunInCommand() {
    return true;
  }

  /**
   * Configure test from data file. Data file is usual java, xml or whatever file that needs to be tested except it
   * has <caret> marker where caret should be placed when file is loaded in editor and <selection></selection>
   * denoting selection bounds.
   *
   * @param relativePath - relative path from %IDEA_INSTALLATION_HOME%/testData/
   */
  protected void configureByFile(@TestDataFile @NonNls @NotNull String relativePath) {
    try {
      String fullPath = getTestDataPath() + relativePath;
      final File ioFile = new File(fullPath);
      checkCaseSensitiveFS(fullPath, ioFile);
      String fileText = FileUtilRt.loadFile(ioFile, CharsetToolkit.UTF8, true);
      configureFromFileText(ioFile.getName(), fileText);
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  @NotNull
  protected String getAnswerFilePath() {
    return getTestDataPath() + myFileSuffix + ".txt";
  }

  @NonNls
  @NotNull
  protected String getTestDataPath() {
    if (myTestDataPath != null) {
      return myTestDataPath;
    }
    return PathManagerEx.getTestDataPath();
  }

  @NotNull
  protected VirtualFile getVirtualFile(@NonNls @NotNull String filePath) {
    String fullPath = getTestDataPath() + filePath;

    final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/'));
    assertNotNull("file " + fullPath + " not found", vFile);
    return vFile;
  }

  /**
   * Same as configureByFile but text is provided directly.
   * @param fileName - name of the file.
   * @param fileText - data file text.
   */
  @NotNull
  protected Document configureFromFileText(@NonNls @NotNull final String fileName, @NonNls @NotNull final String fileText) {
    return configureFromFileText(fileName, fileText, false);
  }

  /**
   * Same as configureByFile but text is provided directly.
   * @param fileName - name of the file.
   * @param fileText - data file text.
   * @param checkCaret - if true, if will be verified that file contains at least one caret or selection marker
   */
  @NotNull
  protected Document configureFromFileText(@NonNls @NotNull final String fileName,
                                           @NonNls @NotNull final String fileText,
                                           boolean checkCaret) {
    return WriteCommandAction.writeCommandAction(null).compute(() -> {
      final Document fakeDocument = new DocumentImpl(fileText);

      EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);
      if (checkCaret) {
        assertTrue("No caret specified in " + fileName, caretsState.hasExplicitCaret());
      }

      String newFileText = fakeDocument.getText();
      Document document;
      try {
        document = setupFileEditorAndDocument(fileName, newFileText);
      }
      catch (IOException e) {
        throw new RuntimeException(e);
      }
      EditorTestUtil.setCaretsAndSelection(getEditor(), caretsState);
      setupEditorForInjectedLanguage();
      getIndexingMode().ensureIndexingStatus(getProject());
      return document;
    });
  }

  @NotNull
  protected Editor configureFromFileTextWithoutPSI(@NonNls @NotNull final String fileText) {
    return WriteCommandAction.writeCommandAction(getProject()).compute(() -> {
      final Document fakeDocument = EditorFactory.getInstance().createDocument(fileText);
      EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);

      String newFileText = fakeDocument.getText();
      Document document = EditorFactory.getInstance().createDocument(newFileText);
      final Editor editor = EditorFactory.getInstance().createEditor(document, getProject());
      ((EditorImpl)editor).setCaretActive();

      EditorTestUtil.setCaretsAndSelection(editor, caretsState);
      getIndexingMode().ensureIndexingStatus(getProject());
      return editor;
    });
  }

  @NotNull
  protected Editor createEditor(@NotNull VirtualFile file) {
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    Editor editor = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), file, 0), false);
    DaemonCodeAnalyzer.getInstance(getProject()).restart();
    assertNotNull(editor);
    ((EditorImpl)editor).setCaretActive();
    getIndexingMode().ensureIndexingStatus(getProject());
    return editor;
  }

  @NotNull
  private Document setupFileEditorAndDocument(@NotNull String relativePath, @NotNull String fileText) throws IOException {
    EncodingProjectManager.getInstance(getProject()).setEncoding(null, StandardCharsets.UTF_8);
    PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
    deleteVFile();

    myEditor = createSaveAndOpenFile(relativePath, fileText);
    myVFile = FileDocumentManager.getInstance().getFile(getEditor().getDocument());
    myFile = getPsiManager().findFile(myVFile);
    getIndexingMode().ensureIndexingStatus(getProject());
    return getEditor().getDocument();
  }

  @NotNull
  protected Editor createSaveAndOpenFile(@NotNull String relativePath, @NotNull String fileText) {
    Editor editor = createEditor(VfsTestUtil.createFile(getSourceRoot(), relativePath, fileText));
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    getIndexingMode().ensureIndexingStatus(getProject());
    return editor;
  }

  @NotNull
  protected static VirtualFile createAndSaveFile(@NotNull String relativePath, @NotNull String fileText) {
    return VfsTestUtil.createFile(getSourceRoot(), relativePath, fileText);
  }

  protected void setupEditorForInjectedLanguage() {
    if (getEditor() != null) {
      Editor hostEditor = getEditor() instanceof EditorWindow ? ((EditorWindow)getEditor()).getDelegate() : getEditor();
      PsiFile hostFile = myFile == null ? null : InjectedLanguageManager.getInstance(getProject()).getTopLevelFile(myFile);
      final Ref<EditorWindow> editorWindowRef = new Ref<>();
      hostEditor.getCaretModel().runForEachCaret(caret -> {
        Editor editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(hostEditor, hostFile);
        if (caret == hostEditor.getCaretModel().getPrimaryCaret() && editor instanceof EditorWindow) {
          editorWindowRef.set((EditorWindow)editor);
        }
      });
      if (!editorWindowRef.isNull()) {
        myEditor = editorWindowRef.get();
        myFile = editorWindowRef.get().getInjectedFile();
        myVFile = myFile.getVirtualFile();
      }
    }
  }

  private void deleteVFile() throws IOException {
    if (myVFile != null) {
      if (myVFile instanceof VirtualFileWindow) myVFile = ((VirtualFileWindow)myVFile).getDelegate();
      WriteAction.run(() -> {
        // avoid messing with invalid files, in case someone calls configureXXX() several times
        PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
        FileEditorManager.getInstance(getProject()).closeFile(myVFile);
        myVFile.delete(getProject());
      });
      getIndexingMode().ensureIndexingStatus(getProject());
    }
  }

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    getIndexingMode().setUpTest(getProject(), getTestRootDisposable());
  }

  @Before  // runs after (all overrides of) setUp()
  public void before() throws Throwable {
    getIndexingMode().ensureIndexingStatus(getProject());
  }

  @Override
  protected void tearDown() throws Exception {
    try {
      Project project = getProject();
      if (myIndexingMode != null && project != null) {
        myIndexingMode.tearDownTest(project);

        FileEditorManager editorManager = FileEditorManager.getInstance(project);
        for (VirtualFile openFile : editorManager.getOpenFiles()) {
          editorManager.closeFile(openFile);
        }
      }
      deleteVFile();
      myEditor = null;
      myFile = null;
      myVFile = null;
    }
    catch (Throwable e) {
      addSuppressedException(e);
    }
    finally {
      super.tearDown();
    }
  }

  /**
   * Validates that content of the editor as well as caret and selection matches one specified in data file that
   * should be formed with the same format as one used in configureByFile
   * @param expectedFilePath - relative path from %IDEA_INSTALLATION_HOME%/testData/
   */
  protected void checkResultByFile(@TestDataFile @NonNls @NotNull String expectedFilePath) {
    checkResultByFile(null, expectedFilePath, false);
  }

  /**
   * Validates that content of the editor as well as caret and selection matches one specified in data file that
   * should be formed with the same format as one used in configureByFile
   * @param message - this check specific message. Added to text, caret position, selection checking. May be null
   * @param expectedFilePath - relative path from %IDEA_INSTALLATION_HOME%/testData/
   * @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing.
   */
  protected void checkResultByFile(@Nullable String message, @TestDataFile @NotNull String expectedFilePath, final boolean ignoreTrailingSpaces) {
    bringRealEditorBack();

    PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
    if (ignoreTrailingSpaces) {
      final Editor editor = getEditor();
      TrailingSpacesStripper.strip(editor.getDocument(), false, true);
      EditorUtil.fillVirtualSpaceUntilCaret(editor);
    }

    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

    String fullPath = getTestDataPath() + expectedFilePath;

    File ioFile = new File(fullPath);

    assertTrue(getMessage("Cannot find file " + fullPath, message), ioFile.exists());
    String fileText;
    try {
     checkCaseSensitiveFS(fullPath, ioFile);
      fileText = FileUtil.loadFile(ioFile, StandardCharsets.UTF_8);
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
    checkResultByText(message, StringUtil.convertLineSeparators(fileText), ignoreTrailingSpaces, getTestDataPath() + "/" + expectedFilePath);
  }

  /**
   * Same as checkResultByFile but text is provided directly.
   */
  protected void checkResultByText(@NonNls @NotNull String expectedFileText) {
    checkResultByText(null, expectedFileText, false, null);
  }

  /**
   * Same as checkResultByFile but text is provided directly.
   * @param message - this check specific message. Added to text, caret position, selection checking. May be null
   * @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing.
   */
  protected void checkResultByText(final String message, @NotNull String expectedFileText, final boolean ignoreTrailingSpaces) {
    checkResultByText(message, expectedFileText, ignoreTrailingSpaces, null);
  }

  /**
   * Same as checkResultByFile but text is provided directly.
   * @param message - this check specific message. Added to text, caret position, selection checking. May be null
   * @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing.
   */
  protected void checkResultByText(final String message, @NotNull String expectedFileText, final boolean ignoreTrailingSpaces, final String filePath) {
    bringRealEditorBack();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    ApplicationManager.getApplication().runWriteAction(() -> {
      final Document document = EditorFactory.getInstance().createDocument(expectedFileText);

      if (ignoreTrailingSpaces) {
        ((DocumentImpl)document).stripTrailingSpaces(getProject());
      }

      EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(document);

      PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
      String newFileText = document.getText();

      PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
      String fileText1 = myFile.getText();
      String failMessage = getMessage("Text mismatch", message);
      if (filePath != null && !newFileText.equals(fileText1)) {
        throw new FileComparisonFailure(failMessage, newFileText, fileText1, filePath);
      }
      assertEquals(failMessage, newFileText, fileText1);

      EditorTestUtil.verifyCaretAndSelectionState(getEditor(), carets, message);
    });
  }

  protected void checkResultByTextWithoutPSI(final String message,
                                                    @NotNull final Editor editor,
                                                    @NotNull final String fileText,
                                                    final boolean ignoreTrailingSpaces,
                                                    final String filePath) {
    ApplicationManager.getApplication().runWriteAction(() -> {
      final Document fakeDocument = EditorFactory.getInstance().createDocument(fileText);

      if (ignoreTrailingSpaces) {
        ((DocumentImpl)fakeDocument).stripTrailingSpaces(getProject());
      }

      EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);

      String newFileText = fakeDocument.getText();
      String fileText1 = editor.getDocument().getText();
      String failMessage = getMessage("Text mismatch", message);
      if (filePath != null && !newFileText.equals(fileText1)) {
        throw new FileComparisonFailure(failMessage, newFileText, fileText1, filePath);
      }
      assertEquals(failMessage, newFileText, fileText1);

      EditorTestUtil.verifyCaretAndSelectionState(editor, carets, message);
    });
  }

  @NotNull
  private static String getMessage(@NonNls @NotNull String engineMessage, String userMessage) {
    if (userMessage == null) return engineMessage;
    return userMessage + " [" + engineMessage + "]";
  }

  /**
   * @return Editor used in test.
   */
  protected Editor getEditor() {
    return myEditor;
  }

  /**
   * @return PsiFile opened in editor used in test
   */
  protected PsiFile getFile() {
    return myFile;
  }

  protected VirtualFile getVFile() {
    return myVFile;
  }

  protected void bringRealEditorBack() {
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    if (getEditor() instanceof EditorWindow) {
      Document document = ((DocumentWindow)getEditor().getDocument()).getDelegate();
      myFile = PsiDocumentManager.getInstance(getProject()).getPsiFile(document);
      myEditor = ((EditorWindow)getEditor()).getDelegate();
      myVFile = myFile.getVirtualFile();
    }
  }

  protected void caretRight() {
    caretRight(getEditor());
  }
  public void caretRight(@NotNull Editor editor) {
    executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT, editor);
  }

  protected void caretUp() {
    caretUp(getEditor());
  }

  public void caretUp(@NotNull Editor editor) {
    executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP, editor);
  }

  protected void deleteLine() {
    deleteLine(getEditor(),getProject());
  }
  public static void deleteLine(@NotNull Editor editor, Project project) {
    executeAction(IdeActions.ACTION_EDITOR_DELETE_LINE, editor,project);
  }

  protected void type(@NonNls @NotNull String s) {
    for (char c : s.toCharArray()) {
      type(c);
    }
  }
  protected void type(char c) {
    type(c, getEditor(),getProject());
  }

  public static void type(char c, @NotNull Editor editor, Project project) {
    if (c == '\n') {
      executeAction(IdeActions.ACTION_EDITOR_ENTER, editor,project);
    }
    else {
      DataContext dataContext = DataManager.getInstance().getDataContext();
      TypedAction action = TypedAction.getInstance();
      action.actionPerformed(editor, c, dataContext);
    }
  }

  protected void backspace() {
    backspace(getEditor(),getProject());
  }

  public static void backspace(@NotNull final Editor editor, Project project) {
    executeAction(IdeActions.ACTION_EDITOR_BACKSPACE, editor,project);
  }

  protected void ctrlShiftF7() {
    HighlightUsagesHandler.invoke(getProject(), getEditor(), getFile());
  }

  protected void ctrlW() {
    ctrlW(getEditor(),getProject());
  }

  public static void ctrlW(@NotNull Editor editor, Project project) {
    executeAction(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET, editor,project);
  }

  public void ctrlD() {
    ctrlD(getEditor(),getProject());
  }
  public static void ctrlD(@NotNull Editor editor, Project project) {
    executeAction(IdeActions.ACTION_EDITOR_DUPLICATE, editor, project);
  }

  protected void delete() {
    delete(getEditor(), getProject());
  }
  public static void delete(@NotNull final Editor editor, Project project) {
    executeAction(IdeActions.ACTION_EDITOR_DELETE, editor, project);
  }

  protected void home() {
    executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_START);
  }

  protected void end() {
    executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END);
  }

  protected void homeWithSelection() {
    executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_START_WITH_SELECTION);
  }

  protected void endWithSelection() {
    executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END_WITH_SELECTION);
  }

  protected void copy() {
    executeAction(IdeActions.ACTION_EDITOR_COPY);
  }

  protected void paste() {
    executeAction(IdeActions.ACTION_EDITOR_PASTE);
  }

  protected void moveCaretToPreviousWordWithSelection() {
    executeAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD_WITH_SELECTION);
  }

  protected void moveCaretToNextWordWithSelection() {
    executeAction(IdeActions.ACTION_EDITOR_NEXT_WORD_WITH_SELECTION);
  }

  protected void previousWord() {
    executeAction(IdeActions.ACTION_EDITOR_PREVIOUS_WORD);
  }

  protected void nextWord() {
    executeAction(IdeActions.ACTION_EDITOR_NEXT_WORD);
  }

  protected void cutLineBackward() {
    executeAction("EditorCutLineBackward");
  }

  protected void cutToLineEnd() {
    executeAction("EditorCutLineEnd");
  }

  protected void deleteToLineStart() {
    executeAction("EditorDeleteToLineStart");
  }

  protected void deleteToLineEnd() {
    executeAction("EditorDeleteToLineEnd");
  }

  protected void killToWordStart() {
    executeAction("EditorKillToWordStart");
  }

  protected void killToWordEnd() {
    executeAction("EditorKillToWordEnd");
  }

  protected void killRegion() {
    executeAction("EditorKillRegion");
  }

  protected void killRingSave() {
    executeAction("EditorKillRingSave");
  }

  protected void unindent() {
    executeAction("EditorUnindentSelection");
  }

  protected void selectLine() {
    executeAction("EditorSelectLine");
  }

  protected void left() {
    executeAction("EditorLeft");
  }

  protected void right() {
    executeAction("EditorRight");
  }

  protected void leftWithSelection() {
    executeAction("EditorLeftWithSelection");
  }

  protected void rightWithSelection() {
    executeAction("EditorRightWithSelection");
  }

  protected void up() {
    executeAction("EditorUp");
  }

  protected void down() {
    executeAction("EditorDown");
  }

  protected void lineComment() {
    executeAction(IdeActions.ACTION_COMMENT_LINE);
  }

  protected void executeAction(@NonNls @NotNull final String actionId) {
    executeAction(actionId, getEditor());
  }
  protected void executeAction(@NonNls @NotNull final String actionId, @NotNull final Editor editor) {
    executeAction(actionId, editor, getProject());
  }
  public static void executeAction(@NonNls @NotNull final String actionId, @NotNull final Editor editor, Project project) {
    CommandProcessor.getInstance().executeCommand(project, () -> EditorTestUtil.executeAction(editor, actionId, true), "", null, editor.getDocument());
  }

  @NotNull
  protected DataContext getCurrentEditorDataContext() {
    final DataContext defaultContext = DataManager.getInstance().getDataContext();
    return dataId -> {
      if (CommonDataKeys.EDITOR.is(dataId)) {
        return getEditor();
      }
      if (CommonDataKeys.PROJECT.is(dataId)) {
        return getProject();
      }
      if (CommonDataKeys.PSI_FILE.is(dataId)) {
        return getFile();
      }
      if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        PsiFile file = getFile();
        if (file == null) return null;
        Editor editor = getEditor();
        if (editor == null) return null;
        return file.findElementAt(editor.getCaretModel().getOffset());
      }
      return defaultContext.getData(dataId);
    };
  }

  /**
   * file parameterized tests support
   * @see FileBasedTestCaseHelperEx
   * @Parameterized.Parameter fields are injected on parameterized test creation.
   */
  @Parameterized.Parameter
  public String myFileSuffix;

  /**
   * path to the root of test data in case of com.intellij.testFramework.FileBasedTestCaseHelperEx
   * or
   * path to the directory with current test data in case of @TestDataPath
   */
  @Parameterized.Parameter(1)
  public String myTestDataPath;

  @Parameterized.Parameters(name = "{0}")
  public static List<Object[]> params() {
    return Collections.emptyList();
  }

  @com.intellij.testFramework.Parameterized.Parameters(name = "{0}")
  public static List<Object[]> params(@NotNull Class<?> klass) throws Throwable{
    final Object testCase = klass.newInstance();
    if (!(testCase instanceof FileBasedTestCaseHelper)) {
      fail("Parameterized test should implement FileBasedTestCaseHelper");
    }

    try {
      PathManagerEx.replaceLookupStrategy(klass, com.intellij.testFramework.Parameterized.class);
    }
    catch (IllegalArgumentException ignore) {
      //allow to run out of idea project
    }

    final FileBasedTestCaseHelper fileBasedTestCase = (FileBasedTestCaseHelper)testCase;

    String testDataPath;
    if (testCase instanceof LightPlatformCodeInsightTestCase) {
      testDataPath = ((LightPlatformCodeInsightTestCase)testCase).getTestDataPath();
    }
    else {
      try {
        Method dataPath = klass.getDeclaredMethod("getTestDataPath");
        dataPath.setAccessible(true);
        testDataPath = (String)dataPath.invoke(fileBasedTestCase);
      }
      catch (Throwable e) {
        testDataPath = PathManagerEx.getTestDataPath();
      }
    }

    File testDir = null;
    if (fileBasedTestCase instanceof FileBasedTestCaseHelperEx) {
      testDir = new File(testDataPath, ((FileBasedTestCaseHelperEx)fileBasedTestCase).getRelativeBasePath());
    } else {
      final TestDataPath annotation = klass.getAnnotation(TestDataPath.class);
      if (annotation == null) {
        fail("TestCase should implement com.intellij.testFramework.FileBasedTestCaseHelperEx or be annotated with com.intellij.testFramework.TestDataPath");
      } else {
        final String trimmedRoot = StringUtil.trimStart(StringUtil.trimStart(annotation.value(), "$CONTENT_ROOT"), "$PROJECT_ROOT");
        final String lastPathComponent = new File(testDataPath).getName();
        final int idx = trimmedRoot.indexOf(lastPathComponent);
        testDataPath = testDataPath.replace(File.separatorChar, '/') + (idx > 0 ? trimmedRoot.substring(idx + lastPathComponent.length()) : trimmedRoot);
        testDir = new File(testDataPath);
      }
    }

    final File[] files = testDir.listFiles();

    if (files == null) {
      fail("Test files not found in " + testDir.getPath());
    }

    final Set<String> beforeFileSuffixes = new HashSet<>();
    final Set<String> afterFileSuffixes = new HashSet<>();
    final List<Object[]> result = new ArrayList<>();
    for (File file : files) {
      final String fileSuffix = fileBasedTestCase.getFileSuffix(file.getName());
      String fileAfterSuffix = fileBasedTestCase.getBaseName(file.getName());
      if (fileAfterSuffix != null) {
        afterFileSuffixes.add(fileAfterSuffix);
      }
      if (fileSuffix != null) {
        beforeFileSuffixes.add(fileSuffix);
        result.add(new Object[] {fileSuffix, testDataPath});
      }
    }
    afterFileSuffixes.removeAll(beforeFileSuffixes);
    if (!afterFileSuffixes.isEmpty()) {
      fail("'After' file has no corresponding 'before' file: " + String.join(", ", afterFileSuffixes));
    }
    return result;
  }

  @Override
  public String getName() {
    if (myFileSuffix != null) {
      return "test" + myFileSuffix;
    }
    return super.getName();
  }

  protected void setEditor(Editor editor) {
    myEditor = editor;
  }

  protected void setFile(PsiFile file) {
    myFile = file;
  }

  protected void setVFile(VirtualFile virtualFile) {
    myVFile = virtualFile;
  }

  @Override
  public void setIndexingMode(@NotNull IndexingMode mode) {
    myIndexingMode = mode;
  }

  @Override
  public @NotNull IndexingMode getIndexingMode() {
    return myIndexingMode;
  }
}


text:
package cache_test

import (
	"context"
	"fmt"
	"reflect"
	"testing"
	"time"

	"github.com/google/go-cmp/cmp"
	"github.com/stretchr/testify/assert"
	"google.golang.org/protobuf/testing/protocmp"

	core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
	discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
	"github.com/envoyproxy/go-control-plane/pkg/cache/types"
	"github.com/envoyproxy/go-control-plane/pkg/cache/v3"
	rsrc "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
	"github.com/envoyproxy/go-control-plane/pkg/server/stream/v3"
	"github.com/envoyproxy/go-control-plane/pkg/test/resource/v3"
)

func assertResourceMapEqual(t *testing.T, want map[string]types.Resource, got map[string]types.Resource) {
	t.Helper()

	if !cmp.Equal(want, got, protocmp.Transform()) {
		t.Errorf("got resources %v, want %v", got, want)
	}
}

func TestSnapshotCacheDeltaWatch(t *testing.T) {
	c := cache.NewSnapshotCache(false, group{}, logger{t: t})
	watches := make(map[string]chan cache.DeltaResponse)

	// Make our initial request as a wildcard to get all resources and make sure the wildcard requesting works as intended
	for _, typ := range testTypes {
		watches[typ] = make(chan cache.DeltaResponse, 1)
		c.CreateDeltaWatch(&discovery.DeltaDiscoveryRequest{
			Node: &core.Node{
				Id: "node",
			},
			TypeUrl:                typ,
			ResourceNamesSubscribe: names[typ],
		}, stream.NewStreamState(true, nil), watches[typ])
	}

	if err := c.SetSnapshot(context.Background(), key, fixture.snapshot()); err != nil {
		t.Fatal(err)
	}

	versionMap := make(map[string]map[string]string)
	for _, typ := range testTypes {
		t.Run(typ, func(t *testing.T) {
			select {
			case out := <-watches[typ]:
				snapshot := fixture.snapshot()
				assertResourceMapEqual(t, cache.IndexRawResourcesByName(out.(*cache.RawDeltaResponse).Resources), snapshot.GetResources(typ))
				vMap := out.GetNextVersionMap()
				versionMap[typ] = vMap
			case <-time.After(time.Second):
				t.Fatal("failed to receive snapshot response")
			}
		})
	}

	// On re-request we want to use non-wildcard so we can verify the logic path of not requesting
	// all resources as well as individual resource removals
	for _, typ := range testTypes {
		watches[typ] = make(chan cache.DeltaResponse, 1)
		state := stream.NewStreamState(false, versionMap[typ])
		for resource := range versionMap[typ] {
			state.GetSubscribedResourceNames()[resource] = struct{}{}
		}
		c.CreateDeltaWatch(&discovery.DeltaDiscoveryRequest{
			Node: &core.Node{
				Id: "node",
			},
			TypeUrl:                typ,
			ResourceNamesSubscribe: names[typ],
		}, state, watches[typ])
	}

	if count := c.GetStatusInfo(key).GetNumDeltaWatches(); count != len(testTypes) {
		t.Errorf("watches should be created for the latest version, saw %d watches expected %d", count, len(testTypes))
	}

	// set partially-versioned snapshot
	snapshot2 := fixture.snapshot()
	snapshot2.Resources[types.Endpoint] = cache.NewResources(fixture.version2, []types.Resource{resource.MakeEndpoint(clusterName, 9090)})
	if err := c.SetSnapshot(context.Background(), key, snapshot2); err != nil {
		t.Fatal(err)
	}
	if count := c.GetStatusInfo(key).GetNumDeltaWatches(); count != len(testTypes)-1 {
		t.Errorf("watches should be preserved for all but one, got: %d open watches instead of the expected %d open watches", count, len(testTypes)-1)
	}

	// validate response for endpoints
	select {
	case out := <-watches[testTypes[0]]:
		snapshot2 := fixture.snapshot()
		snapshot2.Resources[types.Endpoint] = cache.NewResources(fixture.version2, []types.Resource{resource.MakeEndpoint(clusterName, 9090)})
		assertResourceMapEqual(t, cache.IndexRawResourcesByName(out.(*cache.RawDeltaResponse).Resources), snapshot2.GetResources(rsrc.EndpointType))
		vMap := out.GetNextVersionMap()
		versionMap[testTypes[0]] = vMap
	case <-time.After(time.Second):
		t.Fatal("failed to receive snapshot response")
	}
}

func TestDeltaRemoveResources(t *testing.T) {
	c := cache.NewSnapshotCache(false, group{}, logger{t: t})
	watches := make(map[string]chan cache.DeltaResponse)
	streams := make(map[string]*stream.StreamState)

	for _, typ := range testTypes {
		watches[typ] = make(chan cache.DeltaResponse, 1)
		state := stream.NewStreamState(true, make(map[string]string))
		streams[typ] = &state
		// We don't specify any resource name subscriptions here because we want to make sure we test wildcard
		// functionality. This means we should receive all resources back without requesting a subscription by name.
		c.CreateDeltaWatch(&discovery.DeltaDiscoveryRequest{
			Node: &core.Node{
				Id: "node",
			},
			TypeUrl: typ,
		}, *streams[typ], watches[typ])
	}

	if err := c.SetSnapshot(context.Background(), key, fixture.snapshot()); err != nil {
		t.Fatal(err)
	}

	for _, typ := range testTypes {
		t.Run(typ, func(t *testing.T) {
			select {
			case out := <-watches[typ]:
				snapshot := fixture.snapshot()
				assertResourceMapEqual(t, cache.IndexRawResourcesByName(out.(*cache.RawDeltaResponse).Resources), snapshot.GetResources(typ))
				nextVersionMap := out.GetNextVersionMap()
				streams[typ].SetResourceVersions(nextVersionMap)
			case <-time.After(time.Second):
				t.Fatal("failed to receive a snapshot response")
			}
		})
	}

	// We want to continue to do wildcard requests here so we can later
	// test the removal of certain resources from a partial snapshot
	for _, typ := range testTypes {
		watches[typ] = make(chan cache.DeltaResponse, 1)
		c.CreateDeltaWatch(&discovery.DeltaDiscoveryRequest{
			Node: &core.Node{
				Id: "node",
			},
			TypeUrl: typ,
		}, *streams[typ], watches[typ])
	}

	if count := c.GetStatusInfo(key).GetNumDeltaWatches(); count != len(testTypes) {
		t.Errorf("watches should be created for the latest version, saw %d watches expected %d", count, len(testTypes))
	}

	// set a partially versioned snapshot with no endpoints
	snapshot2 := fixture.snapshot()
	snapshot2.Resources[types.Endpoint] = cache.NewResources(fixture.version2, []types.Resource{})
	if err := c.SetSnapshot(context.Background(), key, snapshot2); err != nil {
		t.Fatal(err)
	}

	// validate response for endpoints
	select {
	case out := <-watches[testTypes[0]]:
		snapshot2 := fixture.snapshot()
		snapshot2.Resources[types.Endpoint] = cache.NewResources(fixture.version2, []types.Resource{})
		assertResourceMapEqual(t, cache.IndexRawResourcesByName(out.(*cache.RawDeltaResponse).Resources), snapshot2.GetResources(rsrc.EndpointType))
		nextVersionMap := out.GetNextVersionMap()

		// make sure the version maps are different since we no longer are tracking any endpoint resources
		if reflect.DeepEqual(streams[testTypes[0]].GetResourceVersions(), nextVersionMap) {
			t.Fatalf("versionMap for the endpoint resource type did not change, received: %v, instead of an empty map", nextVersionMap)
		}
	case <-time.After(time.Second):
		t.Fatal("failed to receive snapshot response")
	}
}

func TestConcurrentSetDeltaWatch(t *testing.T) {
	c := cache.NewSnapshotCache(false, group{}, logger{t: t})
	for i := 0; i < 50; i++ {
		version := fmt.Sprintf("v%d", i)
		func(i int) {
			t.Run(fmt.Sprintf("worker%d", i), func(t *testing.T) {
				t.Parallel()
				id := fmt.Sprintf("%d", i%2)
				responses := make(chan cache.DeltaResponse, 1)
				if i < 25 {
					snap, err := cache.NewSnapshot("", map[rsrc.Type][]types.Resource{})
					if err != nil {
						t.Fatal(err)
					}
					snap.Resources[types.Endpoint] = cache.NewResources(version, []types.Resource{resource.MakeEndpoint(clusterName, uint32(i))})
					if err := c.SetSnapshot(context.Background(), key, snap); err != nil {
						t.Fatalf("snapshot failed: %s", err)
					}
				} else {
					cancel := c.CreateDeltaWatch(&discovery.DeltaDiscoveryRequest{
						Node: &core.Node{
							Id: id,
						},
						TypeUrl:                rsrc.EndpointType,
						ResourceNamesSubscribe: []string{clusterName},
					}, stream.NewStreamState(false, make(map[string]string)), responses)

					defer cancel()
				}
			})
		}(i)
	}
}

type testKey struct{}

func TestSnapshotDeltaCacheWatchTimeout(t *testing.T) {
	c := cache.NewSnapshotCache(true, group{}, logger{t: t})

	// Create a non-buffered channel that will block sends.
	watchCh := make(chan cache.DeltaResponse)
	state := stream.NewStreamState(false, nil)
	state.SetSubscribedResourceNames(map[string]struct{}{names[rsrc.EndpointType][0]: {}})
	c.CreateDeltaWatch(&discovery.DeltaDiscoveryRequest{
		Node: &core.Node{
			Id: key,
		},
		TypeUrl:                rsrc.EndpointType,
		ResourceNamesSubscribe: names[rsrc.EndpointType],
	}, state, watchCh)

	// The first time we set the snapshot without consuming from the blocking channel, so this should time out.
	ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
	defer cancel()

	err := c.SetSnapshot(ctx, key, fixture.snapshot())
	assert.EqualError(t, err, context.Canceled.Error())

	// Now reset the snapshot with a consuming channel. This verifies that if setting the snapshot fails,
	// we can retry by setting the same snapshot. In other words, we keep the watch open even if we failed
	// to respond to it within the deadline.
	watchTriggeredCh := make(chan cache.DeltaResponse)
	go func() {
		response := <-watchCh
		watchTriggeredCh <- response
		close(watchTriggeredCh)
	}()

	err = c.SetSnapshot(context.WithValue(context.Background(), testKey{}, "bar"), key, fixture.snapshot())
	assert.NoError(t, err)

	// The channel should get closed due to the watch trigger.
	select {
	case response := <-watchTriggeredCh:
		// Verify that we pass the context through.
		assert.Equal(t, response.GetContext().Value(testKey{}), "bar")
	case <-time.After(time.Second):
		t.Fatalf("timed out")
	}
}

func TestSnapshotCacheDeltaWatchCancel(t *testing.T) {
	c := cache.NewSnapshotCache(true, group{}, logger{t: t})
	for _, typ := range testTypes {
		responses := make(chan cache.DeltaResponse, 1)
		cancel := c.CreateDeltaWatch(&discovery.DeltaDiscoveryRequest{
			Node: &core.Node{
				Id: key,
			},
			TypeUrl:                typ,
			ResourceNamesSubscribe: names[typ],
		}, stream.NewStreamState(false, make(map[string]string)), responses)

		// Cancel the watch
		cancel()
	}
	// c.GetStatusKeys() should return at least 1 because we register a node ID with the above watch creations
	if keys := c.GetStatusKeys(); len(keys) == 0 {
		t.Errorf("expected to see a status info registered for watch, saw %d entries", len(keys))
	}

	for _, typ := range testTypes {
		if count := c.GetStatusInfo(key).GetNumDeltaWatches(); count > 0 {
			t.Errorf("watches should be released for %s", typ)
		}
	}

	if s := c.GetStatusInfo("missing"); s != nil {
		t.Errorf("should not return a status for unknown key: got %#v", s)
	}
}


text:
package com.google.gwt.debugpanel.common;

/**
 * Turns a {@link Throwable} into an {@link ExceptionData} object for transport
 * via a {@link StatisticsEvent}.
 */
public interface ExceptionSerializer {
  public ExceptionData serialize(Throwable t);
}


text:
package org.bubblecloud.zigbee.api.cluster.impl;

import org.bubblecloud.zigbee.api.cluster.impl.api.core.Reporter;
import org.bubblecloud.zigbee.network.ZigBeeEndpoint;
import org.bubblecloud.zigbee.api.ZigBeeDeviceException;
import org.bubblecloud.zigbee.api.cluster.general.LevelControl;
import org.bubblecloud.zigbee.api.cluster.general.event.CurrentLevelListener;
import org.bubblecloud.zigbee.api.cluster.impl.event.CurrentLevelBridgeListeners;
import org.bubblecloud.zigbee.api.ReportingConfiguration;
import org.bubblecloud.zigbee.api.cluster.impl.api.core.Attribute;
import org.bubblecloud.zigbee.v3.model.Status;
import org.bubblecloud.zigbee.api.cluster.impl.api.core.ZigBeeClusterException;
import org.bubblecloud.zigbee.api.cluster.impl.api.global.DefaultResponse;
import org.bubblecloud.zigbee.api.cluster.impl.general.LevelControlCluster;

/**
 * @author Stefano "Kismet" Lenzi
 * @author Francesco Furfari
 * @version $LastChangedRevision: 799 $ ($LastChangedDate: 2013-08-06 19:00:05 +0300 (Tue, 06 Aug 2013) $)
 */
public class LevelControlImpl implements LevelControl {

    private LevelControlCluster levelControlCluster;
    private Attribute currentLevel;
    private Attribute remainingTime;
    private Attribute onOffTransitionTime;
    private Attribute onLevel;
    private final CurrentLevelBridgeListeners eventBridge;

    public LevelControlImpl(ZigBeeEndpoint zbDevice) {
        levelControlCluster = new LevelControlCluster(zbDevice);
        currentLevel = levelControlCluster.getAttributeCurrentLevel();
        remainingTime = levelControlCluster.getAttributeRemainingTime();
        onOffTransitionTime = levelControlCluster.getAttributeOnOffTransitionTime();
        onLevel = levelControlCluster.getAttributeOnLevel();
        eventBridge = new CurrentLevelBridgeListeners(new ReportingConfiguration(), currentLevel, this);
    }

    public Attribute getCurrentLevel() {
        return currentLevel;
    }

    public Attribute getOnLevel() {
        return onLevel;
    }

    public Attribute getOnOffTransitionTime() {
        return onOffTransitionTime;
    }

    public Attribute getRemainingTime() {
        return remainingTime;
    }

    public void move(byte mode, short rate) throws ZigBeeDeviceException {
        try {
            DefaultResponse response = (DefaultResponse) levelControlCluster.move(mode, rate);
            if (!response.getStatus().equals(Status.SUCCESS))
                throw new ZigBeeDeviceException(response.getStatus().toString());
        } catch (ZigBeeClusterException e) {
            throw new ZigBeeDeviceException(e);
        }
    }

    public void moveWithOnOff(byte mode, short rate) throws ZigBeeDeviceException {
        try {
            DefaultResponse response = (DefaultResponse) levelControlCluster.moveWithOnOff(mode, rate);
            if (!response.getStatus().equals(Status.SUCCESS))
                throw new ZigBeeDeviceException(response.getStatus().toString());
        } catch (ZigBeeClusterException e) {
            throw new ZigBeeDeviceException(e);
        }
    }

    public void moveToLevel(short level, int time) throws ZigBeeDeviceException {
        try {
            DefaultResponse response = (DefaultResponse) levelControlCluster.moveToLevel(level, time);
            if (!response.getStatus().equals(Status.SUCCESS))
                throw new ZigBeeDeviceException(response.getStatus().toString());
        } catch (ZigBeeClusterException e) {
            throw new ZigBeeDeviceException(e);
        }
    }

    public void moveToLevelWithOnOff(short level, int time) throws ZigBeeDeviceException {
        try {
            DefaultResponse response = (DefaultResponse) levelControlCluster.moveToLevelWithOnOff(level, time);
            if (!response.getStatus().equals(Status.SUCCESS))
                throw new ZigBeeDeviceException(response.getStatus().toString());
        } catch (ZigBeeClusterException e) {
            throw new ZigBeeDeviceException(e);
        }
    }

    public void step(byte mode, short step, int time) throws ZigBeeDeviceException {
        try {
            DefaultResponse response = (DefaultResponse) levelControlCluster.step(mode, step, time);
            if (!response.getStatus().equals(Status.SUCCESS))
                throw new ZigBeeDeviceException(response.getStatus().toString());
        } catch (ZigBeeClusterException e) {
            throw new ZigBeeDeviceException(e);
        }
    }

    public void stepWithOnOff(byte mode, short step, int time) throws ZigBeeDeviceException {
        try {
            DefaultResponse response = (DefaultResponse) levelControlCluster.stepWithOnOff(mode, step, time);
            if (!response.getStatus().equals(Status.SUCCESS))
                throw new ZigBeeDeviceException(response.getStatus().toString());
        } catch (ZigBeeClusterException e) {
            throw new ZigBeeDeviceException(e);
        }
    }

    public void stop() throws ZigBeeDeviceException {
        try {
            DefaultResponse response = (DefaultResponse) levelControlCluster.stop();
            if (!response.getStatus().equals(Status.SUCCESS))
                throw new ZigBeeDeviceException(response.getStatus().toString());
        } catch (ZigBeeClusterException e) {
            throw new ZigBeeDeviceException(e);
        }
    }

    public void stopWithOnOff() throws ZigBeeDeviceException {
        try {
            DefaultResponse response = (DefaultResponse) levelControlCluster.stopWithOnOff();
            if (!response.getStatus().equals(Status.SUCCESS))
                throw new ZigBeeDeviceException(response.getStatus().toString());
        } catch (ZigBeeClusterException e) {
            throw new ZigBeeDeviceException(e);
        }
    }

    public Reporter[] getAttributeReporters() {
        return levelControlCluster.getAttributeReporters();
    }

    public int getId() {
        return levelControlCluster.getId();
    }

    public String getName() {
        return levelControlCluster.getName();
    }

    public Attribute getAttribute(int id) {
        Attribute[] attributes = levelControlCluster.getAvailableAttributes();
        for (int i = 0; i < attributes.length; i++) {
            if (attributes[i].getId() == id)
                return attributes[i];
        }
        return null;
    }

    public Attribute[] getAttributes() {
        return levelControlCluster.getAvailableAttributes();
    }

    public boolean subscribe(CurrentLevelListener listener) {
        return eventBridge.subscribe(listener);
    }

    public boolean unsubscribe(CurrentLevelListener listener) {
        return eventBridge.unsubscribe(listener);
    }

}


text:
<resources>
    <string name="app_name">ViewComponent</string>
</resources>


text:
namespace OpenQA.Selenium.DevTools.DOM
{
    using System;
    using Newtonsoft.Json;

    /// <summary>
    /// Fired when `Document` has been totally updated. Node ids are no longer valid.
    /// </summary>
    public sealed class DocumentUpdatedEventArgs : EventArgs
    {
    }
}


text:
CeRTAE [SoftMachine](http://www.certae.org/index.php?id=88) proposes an approach based on DATARUN method. This approach consists in achieving the interfaces of an application by the contruction of views from a standard data model. In other words, you can prototype and export a new application model.
The system architecture is a Web MVC variant, this means that we use the basic concepts of Model, View and Controller adapted to a Web App.

>[GPL License V3](docs/LICENSE.md)

>Suggested IDE : [Aptana Studio 3](http://aptana.com/)

## Table of contents

* [Get Started](#get-started)
  * [Software requirements](#software-requirements)
  * [Install using pip](#install-using-pip)
  * [Deploying as Django app](#deploying-as-django-app)
    * [Production requirements](#production-requirements)
    * [Installation](#installation)
* [Security remarks](#security-remarks)
* [Reusing SoftMachine in customized projects](#reusing-softmachine-in-customized-projects)
  * [Generating an application](#generating-an-application)
  * [Setup a new project](#setup-a-new-project)
  * [Extend a template](#extend-a-template)
  * [Add a new ExtJS app](#add-a-new-extjs-app)
  * [Customizing models](#customizing-models)
    * [Executing JavaScript](#executing-javascript)
    * [Dynamic window](#dynamic-window)
    * [Auto-increment](#auto-increment)
  * [Production](#production)

## Get Started
SoftMachine can be installed and used in two ways:

 1. Using `pip3` to install a standalone Python package you can reuse in new projects
 2. Deploying as a Django application

### Software requirements:

* Ext JS 4.2.1
* Python > 3.5
* Django 1.6.1
* graphviz ([OPTION] For export database diagram)
* south ([OPTION] For export database migration)

For testing:
```
$ pip3 install requests
```

### Install using pip
SoftMachine is best installed via PyPI. To install the latest version, run:
```
pip3 install django-softmachine
```
or Install from github source:
```
pip3 install git+git://github.com/certae/ProtoExt.git
```
Edit your **settings.py** file and add `protoLib` and `prototypeur` to your `INSTALLED_APPS` section:
```python
INSTALLED_APPS = (
    ...
    'protobase',
    'protoLib',
    'prototype',
    'myapp',
)
```
Also edit your **urls.py** and add the following url patterns:
```python
urlpatterns = patterns('',
    # ... omited code
    url(r'^', include('protoLib.urls')),
    url(r'^protoDiagram/', include('dbDesigner.urls')),
)
```
>See [<i class="icon-share"></i> Setup a new project](#setup-a-new-project) section for a detailed description.

### Deploying as Django app

#### Production requirements:

* Python-mysqldb  / PyGreSQL / ...  ( DbServerConector )
* Apache
* Mod_wsgi

#### Installation
Those steps are based on a Ubuntu server, but it is applicable to others Linux distributions.

Hands-on: start by checking Python version in a server terminal, usually Ubuntu comes with Python 2.7. The next step is Django installation, in a terminal type:
```script
sudo apt-get install python-setuptools python-dev build-essential
sudo easy_install pip3
sudo pip3 install Django==1.6.1
```

To verify that Django can be seen by Python, type python from your shell. Then at the Python prompt, try to import Django
```python
>>> import django
>>> print django.get_version()
```

If you are going to use MySQL, you must install the python driver:
```
sudo apt-get install python-mysqldb
```

We assume that Apache web server is already installed, if not:
```
sudo apt-get install apache2
```

And for an easy deploy install:
```
sudo apt-get install libapache2-mod-wsgi
```

Now we are going to configure the web server:
```
sudo vi /etc/apache2/sites-available/default
```

Inside the tag `<VirtualHost *:80>`
insert those lines:
>`Alias /static/admin/ /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/`
`WSGIScriptAlias / /var/www/prototypeur/ProtoExt/src/softmachine/prototypeur.wsgi`

We are almost there, go to the home folder:
`cd /var/www/`
create a new prototypeur directory
`mkdir prototypeur`
and extract the ProtoExt-master.zip (downloaded from https://github.com/victorette/ProtoExt) code inside the prototypeur folder, rename the new folder to ProtoExt.
Go to the new folder and make sure that `settings.py` is following the security remarks mentioned below. The App won't work is this file is configured improperly.

Download Ext JS from [Sencha.com](http://www.sencha.com/products/extjs/download/), extract it in `/var/www/prototypeur/ProtoExt/static` and rename the extracted folder to **extjs**.
Synchronize the database:
`python src/manage.py syncdb`

Make sure that all steps were executed and restart the web server:
`sudo /etc/init.d/apache2 restart`

Open chrome or firefox :

If running from aptana : `http://127.0.0.1:8000/protoExt`

If using Apache : `http://<server_ip>/protoExt`

## Security remarks
In order to achieve the security requirements, the `settings.py` should be modified before deploying the Django project.

`SECRET_KEY`
Instead of hardcoding the secret key in the settings module, we are going to load it from a file:
```python
with open('/etc/secret_key.txt') as f:
    SECRET_KEY = f.read().strip()
```

This file will be generated by CeRTAE upon request.

`DEBUG`
Never enable debug in production so set it to False (`DEBUG = False`)

Split configuration is used to avoid sending sensitive data to GitHub. This configuration is based on DEBUG variable. If debug is enabled the System is going to load "settings_development.py" otherwise it will import "settings_production.py".
```python
if DEBUG :
    from softmachine.settings_development import *
    with open( PPATH + '/src/softmachine/secret_key.txt') as f:
        SECRET_KEY = f.read().strip()
else :
    from softmachine.settings_production import *
    with open('/etc/secret_key.txt') as f:
        SECRET_KEY = f.read().strip()
```
Those files contain information about DATABASES, ALLOWED_HOSTS, TEMPLATE_LOADERS, TEMPLATE_CONTEXT_PROCESSORS, TEMPLATE_DIRS, INSTALLED_APPS and EMAIL configurations.

## Reusing SoftMachine in customized projects

If we run the project as a simple Django application we're able to create a relational database model graphically (like [DBDesigner](http://www.fabforce.net/dbdesigner4/)) or via forms. More details in the [docs](http://certae.github.io/ProtoExt/) *French only.

Once that we've defined our model, entities, attributes and relationships it's possible to create and customize a functional **prototype** (CRUD) based on entities.

If you're ready to generate a new App, follow the steps below. You should also check this [Example](https://github.com/victorette/certae-rai)

### Generating an application
When the prototype is finished we can export the model to generate a new application. The output is a `models.py` file containing the basics for a new Django app.

### Setup a new project
Create a new Django project, if you don't know how, take a look on this [Tutorial](https://docs.djangoproject.com/en/1.6/intro/tutorial01/).
Your new project should looks like:
```
mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
    myapp/
        __init__.py
        models.py
        tests.py
        views.py
```
At this point you should have modified those files **settings.py** and **urls.py** as mentioned in [Install using pip](#install-using-pip) section.

### Extend a template

django-softmachine has two main templates, protoExt.html and protoDebug.html. Both have the same blocks, the difference is that protoExt.html uses minified JavaScript files.
See the code bellow to understand how the template is organized (code outside blocks were omitted).
```html
<!DOCTYPE html>
<html lang="fr">
	<head>
		<meta charset="utf-8">
		{% block sitetitle %}
		<!-- put site title here. i.e.: <title>Proto Certae</title> -->
		{% endblock %}

		{% block meta %}
		<!-- put meta content here. i.e.: <meta name="author" content="CeRTAE U.Laval"> -->
		{% endblock %}

		{% block extjs %}
		<!-- Use this block to replace the extjs implementation-->
		{% endblock %}

		{% block defaultstylesheets %}
		<!-- You can replace all application stylesheets,
		if you don't want to use the default css put something here -->
		{% endblock %}
		{% block extrastylesheets %}{% endblock %}

		{% block extjsloader %}{% endblock %}
		{% block configproperties %}<!-- You can replace application's variables here -->{% endblock %}
		{% block javascript %}{% endblock %}
	</head>
	<body></body>
</html>
```

Now we're going to extend the templates to customize your application. Django's template inheritance mechanism allows templates to extend other templates and replace named blocks within them.
Create a new file inside your templates dir, name it `debug.html` (it's a good idea to start using the debug mode). Replace the blocks as you wish, for consultation, you can see the example below:
```html
{% extends "protoDebug.html" %}

{% block sitetitle %}
<title>RAI Certae</title>
{% endblock %}

{% block meta %}
<meta name="description" content="">
<meta name="author" content="CeRTAE U.Laval">
{% endblock %}

{% block extrastylesheets %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/rai.css">
{% endblock %}

{% block extjsloader %}
<script type="text/javascript">
// Place to use Ext.Loader methods
</script>
{% endblock %}

{% block configproperties %}
<script type="text/javascript" src="{{ STATIC_URL }}js/config/configProperties.js"></script>
{% endblock %}
{% block javascript %}
<script type="text/javascript" src="{{ STATIC_URL }}js/rai/app.js"></script>
{% endblock %}
```

### Add a new ExtJS app

SoftMachine UI is based on ExtJS framework. If you don't like it, you're free to use whatever you want. Just keep in mind that using ExtJS could avoid a lot of hard work :)

So you've decided to use ExtJS. We suppose that you're comfortable with the concept of Single Page Application.
SoftMachine UI application is also extensible, you can create your own app, but your app.js must extend `ProtoUL.Application`
```javascript
Ext.application({
    name: 'RAI',
    paths: {
        'RAI' : 'static/js/rai'
    },

    extend: 'ProtoUL.Application',

    controllers: [
		'RAI.controller.RaccordementController'
	]
});
```

Once this is done you are free to create everything that you want, but to execute you code you must create an especific action inside your model [Executing JavaScript](#executing-javascript).

### Customizing models

#### Executing JavaScript
You have defined a new application and there is a need to use this code for an especific table. Create an action inside `protoExt` and add the parameters `name`, `executeJS` and `jsCode` as you can see in the cexample code :

```python
class MyAmazingTable(ProtoModel):
    # omitted code ...

    protoExt = {
        "actions": [
            { "name": "doAmazingAction", "selectionMode" : "single", "executeJS": True, "jsCode":"Ext.create('RAI.view.raccordement.MainWindow',{selectedModel:selectedKeys}).show();",},
        ],
    }
```
If your action uses a selected row you should also add `selectionMode` (`single` or `multiple`). SoftMachine will validate if there is a row selected, otherwise nothing will happen.
If you need to get the selected row(s), you must send the parameter `selectedKeys` to your Window

#### Dynamic window
You also can execute actions based on dynamic forms. All fields must be defined under `actionParams`

```python
class OtherTable(ProtoModel):

    protoExt = {
        "actions": [
            { "name": "doFindReplace", "selectionMode" : "multi", "refreshOnComplete" : True,
               "actionParams": [
                     {"name" : "fieldName", "type" : "string", "required": True, "tooltip" : "field name (meta)" },
                     {"name" : "oldText", "type" : "string", "required": True, "tooltip" : "Old values: pyreg.sub(); @all for all text" },
                     {"name" : "newText", "type" : "string", "required": True, "tooltip" : "New values" },
                ]
            },
        ],
    }
```
You should take a look on the models code to check other custom actions

#### Auto-increment
If for any unknown reason you need to create *another* auto-increment field, you just need to add the attribute `_autoIncrementField` and specify which column will use the auto-increment, note that this column should be `IntegerField`

```python
class Evaluation(ProtoModel):
    id_evaluation = models.IntegerField(blank = False, null = False)
    date_evaluation = models.DateField(blank = True, null = True)
    auteur_evaluation = models.CharField(blank= True, null= True, max_length= 255)
    description_evaluation = models.TextField(blank = True, null = True)

    _autoIncrementField = 'id_evaluation'
```

### Production
If you're ready to deploy your new App, check the security remarks and the Django documentation ([Deploying Django](https://docs.djangoproject.com/en/dev/howto/deployment/))

> Hint: To serve SoftMachine static files copy `...Python/2.7/lib/python/site-packages/protobase/static` to your local static folder...
0Looking