All Downloads are FREE. Search and download functionalities are using the official Maven repository.

libraries.CodeServer.pec Maven / Gradle / Ivy

The newest version!
define createThesaurus as native method doing:
	Java: prompto.codeserver.CodeServer.createThesaurus();

define serverAboutToStart as method receiving Text{} params doing:
	createThesaurus

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 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 as login, module as 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 as login, module as 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 and Boolean optional returning Integer doing:
	Java: return prompto.codeserver.ModuleProcess.launchIfNeeded(dbId, optional);

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"
	deps = [Dependency from lib]
	module = Script with name as name, 'v0.0.1' as version, description as description and deps as 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"
	deps = [Dependency from lib]
	module = Library with name as name, 'v0.0.1' as version, description as description and deps as 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"
	deps = [Dependency from lib]
	module = Batch with name as name, 'v0.0.1' as version, description as description, startMethod as startMethod and deps as dependencies
	decl = createStartMethod with module as 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"
	deps = [Dependency from lib]
	module = Service with name as name, 'v0.0.1' as version, description as description, serverAboutToStartMethod as serverAboutToStartMethod and deps as dependencies
	decl = createStartMethod with module as 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"
	deps = [Dependency from lib]
	module = WebSite with name as name, 'v0.0.1' as version, description as description, image as image, serverAboutToStartMethod as serverAboutToStartMethod, homePage as homePage and deps as dependencies
	decl = createStartMethod with module as module and serverAboutToStartMethod as name
	page = createHomePage with module as module and homePage as name
	store decl, page, 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 as name, 'v0.0.1' as version, "E" as dialect, "Text{}" as prototype, body as body and module as module
	return decl 


define createHomePage as method receiving module and name doing:
	body = "\n\n\t\n\t\n\t\n\t\tHello!\n\t\n"
	page = TextResource with name as name, 'v0.0.1' as version, "text/html" as mimeType, body as body and module as module
	return 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 exportModule as method receiving dbId doing:
	module = fetch one Module where dbId = dbId
	if module is nothing:
		raise NULL_REFERENCE
	// TODO use reflection once available
	type = ""
	if module is a Batch:
		type = "batch"
	else if module is a Script:
		type = "script"
	else if module is a WebSite:
		type = "website"
	else if module is a Service:
		type = "service"
	else if module is a Library:
		type = "library"
	doc = Document
	doc.type = type
	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
	components = [] as Stuff[]
	fetched = fetch all mutable Stuff where module = module
	for each component in fetched:
		component.module = Nothing 
		components = components + [component]
	doc.components = components
	return Blob from doc




© 2015 - 2025 Weber Informatics LLC | Privacy Policy