Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvergnaud committed Dec 9, 2018
1 parent 1916743 commit cef607a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 304 deletions.
289 changes: 0 additions & 289 deletions AppStore/src/main/resources/libraries/AppStore.pec
Original file line number Diff line number Diff line change
Expand Up @@ -118,292 +118,3 @@ define deployRelease as method receiving dbId, nodeSize, nodeCount and dataCente
timeStamp = now
deployment = Deployment with release as release, nodeSize as nodeSize, nodeCount as nodeCount, dataCenters as dataCenters, author as author and timeStamp as timeStamp
store deployment
define createLibraries as native method doing:
Java: prompto.codefactory.Application.createLibraries();

define serverAboutToStart as method receiving Text<:> params doing:
createLibraries

define lastOpened as storable DateTime attribute
define CodingSession as storable category with attributes login, module and lastOpened
define RecentSession as storable CodingSession

define Stuff as storable category with attributes name, version and module

define storable as storable Boolean attribute
define Declaration as storable Stuff with attributes dialect, storable and body
define AttributeDeclaration as storable Declaration
define CategoryDeclaration as storable Declaration
define WidgetDeclaration as storable CategoryDeclaration
define symbols as storable Text[] attribute
define EnumeratedDeclaration as storable Declaration with attribute symbols
define MethodDeclaration as storable Declaration with attribute prototype
define TestDeclaration as storable Declaration

define Resource as storable Stuff with attribute mimeType
define TextResource as storable Resource with attribute body
define BinaryResource as storable Resource with attribute data

define EditStatus as enumerated Text with symbols:
CLEAN with "CLEAN" as value
CREATED with "CREATED" as value
DELETED with "DELETED" as value
DIRTY with "DIRTY" as value

define editStatus as EditStatus attribute
define stuff as Stuff attribute

define EditedStuff as category with attributes editStatus and stuff

define getRecentModules as method receiving Integer count doing:
login = getHttpUser
if login is nothing:
raise NULL_REFERENCE
sessions = fetch RecentSession 1 to count where login = login order by lastOpened desc
return session.module for each session in sessions

define getAllModules as method doing:
return fetch all Module order by name


define getAllLibraries as method doing:
return fetch all Library order by name, version desc


define getModuleDescription as method receiving dbId and Boolean register doing:
login = getHttpUser
if login is nothing:
raise NULL_REFERENCE
module = fetch one Module where dbId = dbId
if module is nothing:
raise NULL_REFERENCE
if register:
// use this opportunity to keep track of coding sessions
session = CodingSession with login, module and now as lastOpened
store session
// use this opportunity to keep track of recent projects
recent = fetch one mutable RecentSession where login = login and module = module
if recent is nothing:
recent = RecentSession with login, module and now as lastOpened
else:
recent.lastOpened = now
store recent
flush
return module


define getModuleDeclarations as method receiving name and version doing:
login = getHttpUser
if login is nothing:
raise NULL_REFERENCE
module = fetch one Module where name = name and version = version
if module is nothing:
raise NULL_REFERENCE
return fetch all Declaration where module = module


define getModuleDeclarations as method receiving dbId doing:
login = getHttpUser
if login is nothing:
raise NULL_REFERENCE
module = fetch one Module where dbId = dbId
if module is nothing:
raise NULL_REFERENCE
return fetch all Declaration where module = module


define getModuleResources as method receiving name and version doing:
login = getHttpUser
if login is nothing:
raise NULL_REFERENCE
module = fetch one Module where name = name and version = version
if module is nothing:
raise NULL_REFERENCE
return fetch all Resource where module = module


define getModuleResources as method receiving dbId doing:
login = getHttpUser
if login is nothing:
raise NULL_REFERENCE
module = fetch one Module where dbId = dbId
if module is nothing:
raise NULL_REFERENCE
return fetch all Resource where module = module

define getModulePort as native method receiving dbId returning Integer doing:
Java: return prompto.codefactory.ModuleProcess.launchIfNeeded(dbId);

define killModule as native method receiving dbId doing:
Java: prompto.codefactory.ModuleProcess.shutDown(dbId);

define storeEdited as method receiving EditedStuff[] edited doing:
deleted = d1.stuff for each d1 in edited filtered with d where d.editStatus = DELETED
created = d2.stuff for each d2 in edited filtered with d where d.editStatus = CREATED
updated = d3.stuff for each d3 in edited filtered with d where d.editStatus = DIRTY
delete deleted and store created, updated
flush


define createScript as method receiving name, description = nothing doing:
// at minimal, all modules depend on Thesaurus
lib = fetch one Library where name = "Thesaurus"
dependencies = [Dependency from lib]
version = 'v0.0.1'
module = Script with name, version, description and dependencies
store module
flush


define createLibrary as method receiving name, description = nothing doing:
// at minimal, all modules depend on Thesaurus
lib = fetch one Library where name = "Thesaurus"
dependencies = [Dependency from lib]
version = 'v0.0.1'
module = Library with name, version, description and dependencies
store module
flush


define createWebLibrary as method receiving name, description = nothing, widgetLibrary, htmlEngine and uiFramework doing:
// at minimal, all modules depend on Thesaurus
lib = fetch one Library where name = "Thesaurus"
dependencies = [Dependency from lib]
version = 'v0.0.1'
module = WebLibrary with name, version, description, widgetLibrary, htmlEngine, uiFramework and dependencies
store module
flush


define createBatch as method receiving name, description = nothing and startMethod doing:
// at minimal, all modules depend on Thesaurus
lib = fetch one Library where name = "Thesaurus"
dependencies = [Dependency from lib]
version = 'v0.0.1'
module = Batch with name, version, description, startMethod and dependencies
decl = createStartMethod with module and startMethod as name
store decl, module
flush


define createService as method receiving name, description = nothing and serverAboutToStartMethod doing:
// at minimal, all modules depend on Thesaurus
lib = fetch one Library where name = "Thesaurus"
dependencies = [Dependency from lib]
version = 'v0.0.1'
module = Service with name, version, description, serverAboutToStartMethod and dependencies
decl = createStartMethod with module and serverAboutToStartMethod as name
store decl, module
flush


define createWebSite as method receiving name, description = nothing, image = nothing, serverAboutToStartMethod and homePage doing:
// at minimal, all modules depend on Thesaurus
lib = fetch one Library where name = "Thesaurus"
dependencies = [Dependency from lib]
version = 'v0.0.1'
module = WebSite with name, version, description, image, serverAboutToStartMethod, homePage and dependencies
decl = createStartMethod with module and serverAboutToStartMethod as name
resources = createHomeHtmlOrPageResources with module and homePage as name
store decl, resources, module
flush


define createStartMethod as method receiving module and name doing:
body = "define " + name + " as method receiving Text<:> options doing:\n"
body = body + "\tprint \"Hello " + module.name + "\"\n"
decl = MethodDeclaration with name, 'v0.0.1' as version, "E" as dialect, "Text<:>" as prototype, body and module
return decl


define createHomeHtmlOrPageResources as method receiving module and name doing:
if name.endsWith ".page":
return createHomePageResources with module and name
else:
return createHomeHtmlResources with module and name


define createHomeHtmlResources as method receiving module and name doing:
body = "<!DOCTYPE html>\n<html>\n\t<head>\n\t</head>\n\t<body>\n\t\tHello!\n\t</body>\n</html>"
page = TextResource with name, 'v0.0.1' as version, "text/html" as mimeType, body and module
return [page]


define createHomePageResources as method receiving module and name doing:
start = name.indexOf "/"
widgetName = name[start + 1:-6].toCapitalized + "Page"
body = "@PageWidgetOf(\"" + name + "\")\n"
body = body + "widget " + widgetName + " {\n\n"
body = body + "\tHtml method render() {\n"
body = body + "\t\treturn <div>Hello \"" + module.name + "\"!</div>;\n"
body = body + "\t}\n\n}\n"
decl = WidgetDeclaration with widgetName as name, 'v0.0.1' as version, "O" as dialect, body and module
body = "header:\n"
body = body + " title: " + module.name + "\n"
body = body + " icon: favicon.ico\n"
body = body + " widgetLibrary: react-bootstrap-3\n"
body = body + "body:\n"
body = body + " widget: " + widgetName + "\n"
page = TextResource with name, 'v0.0.1' as version, "text/page" as mimeType, body and module
return [decl, page]


define storeModule as method receiving module doing:
store module
flush

define deleteModule as method receiving dbId doing:
module = fetch one Module where dbId = dbId
if module is nothing:
raise NULL_REFERENCE
stuff = fetch all Stuff where module = module
sessions = fetch all RecentSession where module = module
delete stuff, sessions, module, module.dependencies
flush


define getModuleTypeName as method receiving module doing:
// TODO use reflection once available
if module is a Batch:
return "Batch"
else if module is a Script:
return "Script"
else if module is a WebSite:
return "WebSite"
else if module is a Service:
return "Service"
else if module is a Library:
return "Library"
else if module is a WebLibrary:
return "WebLibrary"
else:
return "<unknown>"

define exportModule as method receiving dbId doing:
module = fetch one Module where dbId = dbId
if module is nothing:
raise NULL_REFERENCE
doc = Document
doc.type = getModuleTypeName module
doc.name = module.name
doc.version = module.version
doc.description = module.description
doc.image = module.image
if module is a Batch:
doc.startMethod = module.startMethod
else if module is a Service:
doc.serverAboutToStartMethod = module.serverAboutToStartMethod
if module is a WebSite:
doc.homePage = module.homePage
if module is a WebLibrary:
doc.widgetLibrary = module.widgetLibrary
doc.htmlEngine = module.htmlEngine
doc.uiFramework = module.uiFramework
components = [] as Stuff[]
fetched = fetch all mutable Stuff where module = module
// don't re-export module itself
for each component in fetched:
component.module = Nothing
components = components + [component]
doc.components = components
return Blob from doc
26 changes: 25 additions & 1 deletion Server/src/main/java/prompto/server/AppServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import prompto.security.auth.source.IAuthenticationSource;
import prompto.utils.CmdLineParser;
import prompto.utils.Logger;
import prompto.value.Document;

public class AppServer {

Expand Down Expand Up @@ -169,7 +170,8 @@ public static boolean isStarted() {
return jettyServer!=null && jettyServer.isStarted();
}

public static int getHttpPort() {
/* used by Server.pec */
public static long getHttpPort() {
return jettyServer.getHttpPort();
}

Expand All @@ -190,4 +192,26 @@ public static void createLogin(String login, String password) {
if(source!=null)
source.createLogin(login, password);
}

static ThreadLocal<String> httpUser = new ThreadLocal<>();

/* used by Server.pec */
public static String getHttpUser() {
return httpUser.get();
}

public static void setHttpUser(String user) {
httpUser.set(user);
}

static ThreadLocal<Document> httpSession = new ThreadLocal<>();

/* used by Server.pec */
public static Document getHttpSession() {
return httpSession.get();
}

public static void setHttpSession(Document session) {
httpSession.set(session);
}
}
2 changes: 1 addition & 1 deletion Server/src/main/java/prompto/server/HttpUserReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public abstract class HttpUserReader {
public static void readAndSet(HttpServletRequest request) {
Principal principal = request.getUserPrincipal();
String user = principal!=null ? principal.getName() : "<anonymous>";
Server.setHttpUser(user);
AppServer.setHttpUser(user);

}

Expand Down
2 changes: 1 addition & 1 deletion Server/src/main/java/prompto/server/PromptoServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void readSession(HttpServletRequest req) {
doc = new Document();
req.getSession(true).setAttribute("__prompto_http_session__", doc);
}
Server.setHttpSession(doc);
AppServer.setHttpSession(doc);
}

@Override
Expand Down
15 changes: 5 additions & 10 deletions Server/src/main/resources/libraries/Server.pec
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ define createLogin as native method receiving login and password doing:
Java: $server.createLogin(login, password);

define getHttpUser as native method returning Text doing:
Java: return prompto.server.Server.getHttpUser();
C#: return prompto.server.Server.getHttpUser();
Python2: return getHttpUser() from module: prompto.server.Server
Python3: return getHttpUser() from module: prompto.server.Server
JavaScript: return getHttpUser(); from module: prompto/server/Server.js
Java: return $server.getHttpUser();

define getHttpSession as native method returning Document doing:
Java: return prompto.server.Server.getHttpSession();
C#: return prompto.server.Server.getHttpSession();
Python2: return getHttpSession() from module: prompto.server.Server
Python3: return getHttpSession() from module: prompto.server.Server
JavaScript: return getHttpSession(); from module: prompto/server/Server.js
Java: return $server.getHttpSession();

define getHttpPort as native method returning Integer doing:
Java: return $server.getHttpPort();
2 changes: 1 addition & 1 deletion Server/src/test/java/prompto/server/BaseUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void startAppServer() throws Throwable {
"test-local.yml"
};
TestServer.main(args);
HTTP_PORT = AppServer.getHttpPort();
HTTP_PORT = (int)AppServer.getHttpPort();
}

@AfterClass
Expand Down
2 changes: 1 addition & 1 deletion prompto-java

0 comments on commit cef607a

Please sign in to comment.