Skip to content

Commit

Permalink
Merge pull request #679 from AmpersandTarski/development
Browse files Browse the repository at this point in the history
Release 3.8.6
  • Loading branch information
hanjoosten authored Jul 8, 2017
2 parents cba5945 + f9e5366 commit 49946cb
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 26 deletions.
5 changes: 5 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release notes of Ampersand


## v3.8.6 (7 july 2017)
* [Issue #674](https://github.com/AmpersandTarski/Ampersand/issues/674) New feature for ExecEngine to navigate user to other interface
* [Issue #675](https://github.com/AmpersandTarski/Ampersand/issues/675) Extend scope of _NEW in ExecEngine from NewStruct to complete violation statement

## v3.8.5 (12 may 2017)
* [Issue #666](https://github.com/AmpersandTarski/Ampersand/issues/666) A hint message is supplied when a case-incorrect url is used.
* Upgrade LTS Haskell 8.5, which includes GHC 8.0.2
Expand Down
2 changes: 1 addition & 1 deletion ampersand.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ampersand
version: 3.8.5
version: 3.8.6
author: Stef Joosten
maintainer: stef.joosten@ou.nl
synopsis: Toolsuite for automated design of business processes.
Expand Down
3 changes: 3 additions & 0 deletions static/zwolle/api/v1/resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
, 'invariantRulesHold' => $session->database->getInvariantRulesHold()
, 'requestType' => $session->database->getRequestType()
, 'sessionRefreshAdvice' => $session->getSessionRefreshAdvice()
, 'navTo' => $session->getNavToResponse()
);

print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Expand Down Expand Up @@ -151,6 +152,7 @@
, 'invariantRulesHold' => $session->database->getInvariantRulesHold()
, 'requestType' => $session->database->getRequestType()
, 'sessionRefreshAdvice' => $session->getSessionRefreshAdvice()
, 'navTo' => $session->getNavToResponse()
);

print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Expand All @@ -176,6 +178,7 @@
, 'invariantRulesHold' => $session->database->getInvariantRulesHold()
, 'requestType' => $session->database->getRequestType()
, 'sessionRefreshAdvice' => $session->getSessionRefreshAdvice()
, 'navTo' => $session->getNavToResponse()
);

print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Expand Down
3 changes: 2 additions & 1 deletion static/zwolle/app/AmpersandApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ AmpersandApp.config(function(RestangularProvider) {

});

AmpersandApp.run(function(Restangular, $rootScope, $localStorage, $sessionStorage, $location, $route){
AmpersandApp.run(function(Restangular, $rootScope, $localStorage, $sessionStorage, $location, $route, $location){

$sessionStorage.session = {'id' : initSessionId}; // initSessionId provided by index.php on startup application

Expand All @@ -48,6 +48,7 @@ AmpersandApp.run(function(Restangular, $rootScope, $localStorage, $sessionStorag

Restangular.addResponseInterceptor(function(data, operation, what, url, response, deferred){
if(operation != 'get' && operation != 'getList' && data.sessionRefreshAdvice) $rootScope.refreshNavBar();
if(data.navTo != null) $location.url(data.navTo);

return data;
});
Expand Down
7 changes: 7 additions & 0 deletions static/zwolle/extensions/ExecEngine/ExecEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class ExecEngine {
public static $autoRerun;
public static $runCount;

/**
* @var \Ampersand\Core\Atom $_NEW specifies latest atom created by a newstruct function call. Can be (re)used within the scope of one violation statement.
*/
public static $_NEW = null;

public static function run($allRules = false){
$database = Database::singleton();
$logger = Logger::getLogger('EXECENGINE');
Expand Down Expand Up @@ -159,6 +164,8 @@ public static function fixViolations($violations){
throw new Exception("Function '{$function}' does not exists. Create function with {count($params)} parameters", 500);
}
}

self::$_NEW = null; // The newly created atom cannot be (re)used outside the scope of the violation in which it was created.
}
}
}
Expand Down
86 changes: 65 additions & 21 deletions static/zwolle/extensions/ExecEngine/functions/insDelPairAtom.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use Ampersand\Core\Relation;
use Ampersand\Core\Concept;
use Ampersand\Core\Atom;
use Ampersand\Session;
use Ampersand\Extension\ExecEngine\ExecEngine;

/*
Example of rule that automatically inserts pairs into a relation (analogous stuff holds for DelPair):
Expand All @@ -47,19 +49,15 @@ function InsPair($relationName,$srcConceptName,$srcAtom,$tgtConceptName,$tgtAtom
$tgtConcept = Concept::getConceptByLabel($tgtConceptName);
$relation = Relation::getRelation($relationName, $srcConcept, $tgtConcept);

if($srcAtom == "NULL" or $tgtAtom == "NULL") throw new Exception("Use of keyword NULL is deprecated, use '_NEW'", 500);

// if either srcAtomIdStr or tgtAtom is not provided by the pairview function (i.e. value set to '_NULL'): skip the insPair
if($srcAtom == '_NULL' or $tgtAtom == '_NULL'){
Logger::getLogger('EXECENGINE')->debug("InsPair ignored because src and/or tgt atom is _NULL");
return;
}

// if srcAtomIdStr is specified as _NEW, a new atom of srcConcept is created
if($srcAtom == "_NEW") $srcAtom = $srcConcept->createNewAtomId();

// if tgtAtom is specified as _NEW, a new atom of tgtConcept is created
if($tgtAtom == "_NEW") $tgtAtom = $tgtConcept->createNewAtomId();
// if atom id is specified as _NEW, the latest atom created by NewStruct or InsAtom (in this VIOLATION) is used
if($srcAtom == "_NEW") $srcAtom = ExecEngine::$_NEW->id;
if($tgtAtom == "_NEW") $tgtAtom = ExecEngine::$_NEW->id;

$srcAtomIds = explode('_AND', $srcAtom);
$tgtAtomIds = explode('_AND', $tgtAtom);
Expand Down Expand Up @@ -94,14 +92,16 @@ function DelPair($relationName,$srcConceptName,$srcAtom,$tgtConceptName,$tgtAtom
$tgtConcept = Concept::getConceptByLabel($tgtConceptName);
$relation = Relation::getRelation($relationName, $srcConcept, $tgtConcept);

if($srcAtom == "NULL" or $tgtAtom == "NULL") throw new Exception("Use of keyword NULL is deprecated, use '_NEW'", 500);

// if either srcAtomIdStr or tgtAtom is not provided by the pairview function (i.e. value set to '_NULL'): skip the insPair
if($srcAtom == '_NULL' or $tgtAtom == '_NULL'){
Logger::getLogger('EXECENGINE')->debug("DelPair ignored because src and/or tgt atom is _NULL");
return;
}

// if atom id is specified as _NEW, the latest atom created by NewStruct or InsAtom (in this VIOLATION) is used
if($srcAtom == "_NEW") $srcAtom = ExecEngine::$_NEW->id;
if($tgtAtom == "_NEW") $tgtAtom = ExecEngine::$_NEW->id;

$srcAtoms = explode('_AND', $srcAtom);
$tgtAtoms = explode('_AND', $tgtAtom);
if(count($srcAtoms) > 1) throw new Exception('DelPair function call has more than one src atom', 501); // 501: Not implemented
Expand Down Expand Up @@ -155,6 +155,9 @@ function NewStruct(){ // arglist: ($ConceptC[,$newAtom][,$relation,$srcConcept,$

// Add atom to concept
$atom->addAtom();

// Make newly created atom available within scope of violation for use of other functions
ExecEngine::$_NEW = $atom;

// Next, for every relation that follows in the argument list, we create a link
for ($i = func_num_args() % 5; $i < func_num_args(); $i = $i+5){
Expand Down Expand Up @@ -199,6 +202,9 @@ function InsAtom($conceptName){
$atom = $concept->createNewAtom();
$atom->addAtom(); // insert new atom in database

// Make newly created atom available within scope of violation for use of other functions
ExecEngine::$_NEW = $atom;

Logger::getLogger('EXECENGINE')->debug("Atom '{$atom->__toString()}' created and added to database");

}catch(Exception $e){
Expand All @@ -216,8 +222,11 @@ function InsAtom($conceptName){
function DelAtom($concept, $atomId){
Logger::getLogger('EXECENGINE')->info("DelAtom($concept,$atomId)");
if(func_num_args() != 2) throw new Exception("DelAtom() expects 2 arguments, but you have provided ".func_num_args(), 500);
try{
$atom = new Atom($atomId, Concept::getConceptByLabel($concept));
try{
// if atom id is specified as _NEW, the latest atom created by NewStruct or InsAtom (in this VIOLATION) is used
if($atomId == "_NEW") $atom = ExecEngine::$_NEW;
else $atom = new Atom($atomId, Concept::getConceptByLabel($concept));

$atom->deleteAtom(); // delete atom + all pairs shared with other atoms
Logger::getLogger('EXECENGINE')->debug("Atom '{$atom}' deleted");

Expand Down Expand Up @@ -245,6 +254,11 @@ function MrgAtoms($conceptA, $srcAtomId, $conceptB, $tgtAtomId){
try{
$srcAtom = new Atom($srcAtomId, Concept::getConceptByLabel($conceptA));
$tgtAtom = new Atom($tgtAtomId, Concept::getConceptByLabel($conceptB));

// if atom id is specified as _NEW, the latest atom created by NewStruct or InsAtom (in this VIOLATION) is used
if($srcAtomId == "_NEW") $srcAtom = ExecEngine::$_NEW;
if($tgtAtomId == "_NEW") $tgtAtom = ExecEngine::$_NEW;

$srcAtom->unionWithAtom($tgtAtom); // union of two records plus substitution in all occurences in binary relations.
Logger::getLogger('EXECENGINE')->debug("Atom '{$tgtAtom}' unified with '{$srcAtom}' and then deleted");

Expand All @@ -255,21 +269,24 @@ function MrgAtoms($conceptA, $srcAtomId, $conceptB, $tgtAtomId){
}

/*
ROLE ExecEngine MAINTAINS "SetConcept" -- Adding an atom[ConceptA] as member to ConceptB set. This can only be done when ConceptA and ConceptB are in the same classification tree.
ROLE ExecEngine MAINTAINS "SetConcept" -- Adding an atomId[ConceptA] as member to ConceptB set. This can only be done when ConceptA and ConceptB are in the same classification tree.
RULE "SetConcept": I[ConceptA] |- expr
VIOLATION (TXT "SetConcept;ConceptA;ConceptB;" SRC I)
*/
// Use: VIOLATION (TXT "SetConcept;<ConceptA>;<ConceptB>;<atom>")
function SetConcept($conceptA, $conceptB, $atom){
Logger::getLogger('EXECENGINE')->info("SetConcept($conceptA,$conceptB,$atom)");
// Use: VIOLATION (TXT "SetConcept;<ConceptA>;<ConceptB>;<atomId>")
function SetConcept($conceptA, $conceptB, $atomId){
Logger::getLogger('EXECENGINE')->info("SetConcept($conceptA,$conceptB,$atomId)");
if(func_num_args() != 3) throw new Exception("SetConcept() expects 3 arguments, but you have provided ".func_num_args(), 500);
try{
$database = Database::singleton();

$atom = new Atom($atom, Concept::getConceptByLabel($conceptA));
// if atom id is specified as _NEW, the latest atom created by NewStruct or InsAtom (in this VIOLATION) is used
if($atomId == "_NEW") $atom = ExecEngine::$_NEW;
else $atom = new Atom($atomId, Concept::getConceptByLabel($conceptA));

$conceptB = Concept::getConceptByLabel($conceptB);
$database->atomSetConcept($atom, $conceptB);
Logger::getLogger('EXECENGINE')->debug("Atom '{$atom->__toString()}' added as member to concept '{$conceptB}'");
Logger::getLogger('EXECENGINE')->debug("Atom '{$atom}' added as member to concept '{$conceptB}'");

}catch(Exception $e){
Logger::getUserLogger()->error('SetConcept: ' . $e->getMessage());
Expand All @@ -282,15 +299,18 @@ function SetConcept($conceptA, $conceptB, $atom){
VIOLATION (TXT "ClearConcept;Concept;" SRC I)
*/
// Use: VIOLATION (TXT "ClearConcept;<Concept>;<atom>")
function ClearConcept($concept, $atom){
Logger::getLogger('EXECENGINE')->info("ClearConcept($concept,$atom)");
function ClearConcept($concept, $atomId){
Logger::getLogger('EXECENGINE')->info("ClearConcept($concept,$atomId)");
if(func_num_args() != 2) throw new Exception("ClearConcept() expects 2 arguments, but you have provided ".func_num_args(), 500);
try{
$database = Database::singleton();

$atom = new Atom($atom, Concept::getConceptByLabel($concept));
// if atom id is specified as _NEW, the latest atom created by NewStruct or InsAtom (in this VIOLATION) is used
if($atomId == "_NEW") $atom = ExecEngine::$_NEW;
$atom = new Atom($atomId, Concept::getConceptByLabel($concept));

$database->atomClearConcept($atom);
Logger::getLogger('EXECENGINE')->debug("Atom '{$atom->__toString()}' removed as member from concept '$concept'");
Logger::getLogger('EXECENGINE')->debug("Atom '{$atom}' removed as member from concept '$concept'");

}catch(Exception $e){
Logger::getUserLogger()->error('ClearConcept: ' . $e->getMessage());
Expand Down Expand Up @@ -343,4 +363,28 @@ function SetConceptCond($conceptA, $conceptB, $atom, $bool){
Logger::getUserLogger()->error('SetConceptCond: ' . $e->getMessage());
}
}

function SetNavToOnCommit($navTo){
Logger::getLogger('EXECENGINE')->info("setNavToOnCommit($navTo)");

if(strpos($navTo, '_NEW') !== false){
$navTo = str_replace('_NEW', ExecEngine::$_NEW->id, $navTo); // Replace _NEW with latest atom created by NewStruct or InsAtom (in this VIOLATION)
Logger::getLogger('EXECENGINE')->debug("replaced navTo string with '{$navTo}'");
}

$session = Session::singleton();
$session->navToOnCommit = $navTo;
}

function SetNavToOnRollback($navTo){
Logger::getLogger('EXECENGINE')->info("setNavToOnRollback($navTo)");

if(strpos($navTo, '_NEW') !== false){
$navTo = str_replace('_NEW', ExecEngine::$_NEW->id, $navTo); // Replace _NEW with latest atom created by NewStruct or InsAtom (in this VIOLATION)
Logger::getLogger('EXECENGINE')->debug("replaced navTo string with '{$navTo}'");
}

$session = Session::singleton();
$session->navToOnRollback = $navTo;
}
?>
6 changes: 3 additions & 3 deletions static/zwolle/localSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*************************************************************************************************/
set_time_limit (30);

//Config::set('debugMode', 'global', true); // default = false
//Config::set('debugMode', 'global', true); // production mode = false

// Log file handler
$fileHandler = new \Monolog\Handler\RotatingFileHandler(__DIR__ . '/log/error.log', 0, \Monolog\Logger::WARNING);
Expand Down Expand Up @@ -52,7 +52,7 @@
/**************************************************************************************************
* DATABASE settings
*************************************************************************************************/
// Config::set('dbHost', 'mysqlDatabase', 'localhost');
// Config::set('dbHost', 'mysqlDatabase', '127.0.0.1');
// Config::set('dbUser', 'mysqlDatabase', 'ampersand');
// Config::set('dbPassword', 'mysqlDatabase', 'ampersand');
// Config::set('dbName', 'mysqlDatabase', '');
Expand All @@ -77,4 +77,4 @@
require_once(__DIR__ . '/extensions/ExcelImport/ExcelImport.php'); // Enable ExcelImport


?>
?>
15 changes: 15 additions & 0 deletions static/zwolle/src/Ampersand/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class Session {
*/
private static $_instance = null;

public $navToOnCommit = null;
public $navToOnRollback = null;

/**
* Constructor of Session class
* private to prevent any outside instantiation of this object
Expand Down Expand Up @@ -391,5 +394,17 @@ public function getSessionRefreshAdvice(){
&& ($this->database->getRequestType() == 'promise')
&& $this->database->getInvariantRulesHold();
}

public function getNavToResponse(){
return $this->database->getInvariantRulesHold() ? $this->navToOnCommit : $this->navToOnRollback;
}

public function setNavToOnCommit($navTo){
$this->navToOnCommit = $navTo;
}

public function setNavToOnRollback($navTo){
$this->navToOnRollback = $navTo;
}
}
?>
12 changes: 12 additions & 0 deletions static/zwolle/templates/views/Box-PropertyButton.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$if(verbose)$<!-- Box-PropertyButton.html "$label$" : $expAdl$ :: $source$ * $target$ $if(exprIsUni)$[UNI]$endif$$if(exprIsTot)$[TOT]$endif$ ($if(crudC)$C$else$c$endif$$if(crudR)$R$else$r$endif$$if(crudU)$U$else$u$endif$$if(crudD)$D$else$d$endif$) -->
$endif$

$if(crudR)$
<div ng-repeat="resource in resource['$name$']">
<button class="btn btn-sm btn-primary"
ng-hide="resource.hide.length"
ng-click="resource.property = !resource.property; saveItem(resource, 'property', patchResource);"
ng-disabled="resource.disabled.length">$label$
</button>
</div>
$else$<span><i>N/A</i></span>$endif$
4 changes: 4 additions & 0 deletions static/zwolle/templates/views/STRONG.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- VIEW STRONG: StrongText HTML TEMPLATE "STRONG.html" ENDVIEW -->
$if(exprIsUni)$<strong>{{resource['$name$']}}</strong>$else$<div ng-repeat="atom in resource['$name$']">
<strong>{{atom}}</strong>
</div>$endif$

0 comments on commit 49946cb

Please sign in to comment.