Code Monkey home page Code Monkey logo

damascus's Introduction

Damascus

CI Coverage Status Gitter chat

Damascus is a Liferay Blade tool extension for generating scaffolding of Service builder portlet with CRUD functionality based on a configuration json file, base.json. For more detailed usage, please see this official document

The list of what Damascus automatically generate is as follows

  • CRUD functionality with a model
    • CRUD api / corresponding jsp pages
    • Document & Library access field (if you have a corresponding field in base.json)
    • Assets required field (if you have a corresponding field in base.json)
  • Workflow
  • Trashbox
  • Search (Including Advanced search for individual fields)
  • Comments (Deprecated in 7.2 templates)
  • Related assets
  • Ratings (Deprecated in 7.2 templates)
  • Activities (The activities on the portlet will be recorded and visible on an activity portlet)
  • Multiple service builder portlets at once
  • Exporting entities by xls file format
  • 1..N Relations between models
  • Template generation

Required environment

  • Liferay 7.3 CE GA2 and later.
  • Liferay 7.2 CE GA1 and later.
  • Liferay 7.1 CE GA1 and later.
  • Liferay 7.0 CE GA7 and Liferay DXP SP11 or later versions.
  • Java 1.8
  • gradle 6.7 or above need to be installed
  • jpm needs to be installed. (instruction to install is as follows)

How to Install

Mac

curl https://raw.githubusercontent.com/yasuflatland-lf/damascus/master/installers/global | sudo sh

Windows

  1. Download jpm and install.
  2. Install damascus-all.jar with jpm as follows. jpm install https://github.com/yasuflatland-lf/damascus/raw/master/latest/damascus-all.jar

How to update

  1. Run jpm remove damascus to uninstall damascus.
  2. Remove all files under ${user}/.damascus folder. If you've modified files, please change them accordingly after regenerating configurations and templates.
  3. Follow How to install section to install again

Getting started

Let's make a Todo app with damascus

  1. Create a Liferay workspace with Blade cli or Liferay IDE / Liferay Developer Studio. For more details, please see this document.
  2. After creating Liferay workspace, navigate to under modules folder and run damascus init -c Todo -p com.liferay.sb.test -v 7.3
  3. Navigate to todo folder. You'll see base.json file is created. For detailed configuration, please see the official documentation. Just for demonstration now, we'll create a scaffolding as it is.
  4. Type damascus create and damascus will create a scaffolding service and portlet according to the base.json file.
  5. Start up your Liferay server and in the Todo folder, type blade deploy. Blade will run properly and service and portlet will be deployed.

How to compile Damascus on your own?

  1. Clone this repository to your local. Please make sure you've already installed Gradle 3.0 or above and jpm.
  2. At the root directory, run ./gradlew shadowJar then damascus-all.jar will be created under /build/libs/ directory.
  3. If you've already installed damascus, uninstall it first with jpm remove damascus. Then install your jar with jpm install ./damascus-all.jar.

Proxy settings

Please see more detailed settings here

IDE settings

Damascus is including lombok library, so annotation library for lombok needs to be properly installed on IDEs. Here are how to apply lombok to Eclipse / IntelliJ

Eclipse (Not Liferay Developer Studio)
  1. Download lombok https://projectlombok.org/download
  2. double click lombok.jar and select the directory where eclipse.exe exist
  3. Run ./gradlew eclipse at the project directory and restart IDE, and right click on the project and display context name, and choose gradle > Refresh gradle project
  4. Java files will be displayed properly without errors.
IntelliJ
  1. Preferences - Plugins and search Lombok. Install the Lombok plugin.
  2. Preferences - Build, Execution, Deployment - Compiler - Annotation Processors and check Enable annotation processing

Bug reports

In terms of bugs, please post Github issues or send me a PR. To send me PR, please follow the process below.

  1. Fix bugs at your local
  2. Remove ${user}/.damascus folder.
  3. Run test locally with this command ./gradlew clean test --info and confirm your fix pass all tests.
  4. Send PR to /development repository. I'll create a fix brunch accordingly.

Enhancement requests

A contribution is always welcome! In terms of an Enhancement request, please follow the process below. If you wonder it's a complex feature, please create an issue first and let's discuss. In terms of simple enhancement, please follow steps below.

  1. After implementing your feature, please add a test as well. Spock test is preferable because it's more readable and flexible to add tests later on. To add tests, tests are separated by classes, and in a test class, each test should be written each method basis.
  2. Run test locally with ./gradlew clean test --info until your code pass all tests
  3. Send a PR to /development branch. According to the status of Github Action, I may create a feature branch and request you to make it pass the test on Github Action environment.
  4. After all tests pass on Github Action, will merge into the development branch and release into master at some points according to the impact of the code.

What does Damascus stand for?

Damascus is named after "Damascus blade", which is a strong/sharp blade made out from Damascus steel and forged with lost technology. Liferay has it's an official development tool, "Blade", so I gave this name in the hope of reinforcement or extension of Blade tool.

damascus's People

Contributors

antonlh avatar artus avatar dnebinger avatar gbovyn avatar mario-softbless avatar slemarchand avatar yasuflatland-lf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

damascus's Issues

Add exception message printing at each the catch syntax

At Exception in *ActionCommand.java and *ServiceLocalImpl.java, the root error cause must be displayed on console because it's hard to debug without it.

In case where throwing a custom exception, log.error may be appropriate.

Ability to use user defined valuable in templates.

As a developer, custom variables in templates to manage conditions is helpful. The expected use case is as follows

  1. Define valuables in base.json (extend base.json structure)
  2. Create custom templates and use those conditional values with Freemarker. Maybe storing those data into an associative array.

Template generator from actual code

Motivation

At a project, there's a case where a user wants to use Damascus as a service generator of their custom templates. In that case, users repeat a cycle to generate codes and fix templates accordingly. A functionally to assist the cycle efficiency will be beneficial not only for users but also Damascus contributors as well.

The idea of implementation

Replacement patterns

The default replacement patterns between template value and Keywords (model names, package names and directory names) should be generated in base.json file as optional fields at damascus -init command called.

The fields should be customizable as users may want to add custom patterns as well.

Templates cache is never refreshed

Templates cache is never refreshed : if you build and install a new version of Damascus with modifications in template files, the template files stored in ${HOME}/.damascus/templates are never updated.

getDateTimeFromRequest need to create a empty time instead of throwing Exception when no parameters found

In *LocalServiceImpl#getDateTimeFromRequest, this method should return alternative data instead of throwing an exception when no parameters for date found. Also in the exception, it needs to be printed on the console. The sample code is below.

    public Date getDateTimeFromRequest(PortletRequest request, String prefix) {
        int Year = ParamUtil.getInteger(request, prefix + "Year");
        int Month = ParamUtil.getInteger(request, prefix + "Month") + 1;
        int Day = ParamUtil.getInteger(request, prefix + "Day");
        int Hour = ParamUtil.getInteger(request, prefix + "Hour");
        int Minute = ParamUtil.getInteger(request, prefix + "Minute");
        int AmPm = ParamUtil.getInteger(request, prefix + "AmPm");

        if (AmPm == Calendar.PM) {
            Hour += 12;
        }

        LocalDateTime ldt;
		try {
			ldt = LocalDateTime.of(Year, Month, Day, Hour, Minute, 0);
		} catch (Throwable e) {
			e.printStackTrace();
			Date in = new Date();
			Instant instant = in.toInstant();
			return Date.from(instant);			
		}
		
        return Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
    }

AnnotationTypeMismatchException from JCommander

Hi,

I installed damascus with jpm as indicated in the wiki, but when I run it I get an AnnotationTypeMismatchException error.

I tried to compile it myself, same result as you can see below.

C:\...\damascus\build\libs>java -jar damascus.jar -init Todo -p todo
java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract java.lang.Class[] com.beust.jcommander.Parameter.validateWith() (Found data of type class java.lang.Class[class com.liferay.damascus.cli.validators.ProjectNameValidator])
        at sun.reflect.annotation.AnnotationTypeMismatchExceptionProxy.generateException(Unknown Source)
        at sun.reflect.annotation.AnnotationInvocationHandler.invoke(Unknown Source)
        at com.sun.proxy.$Proxy2.validateWith(Unknown Source)
        at com.beust.jcommander.WrappedParameter.validateWith(WrappedParameter.java:55)
        at com.beust.jcommander.ParameterDescription.validateParameter(ParameterDescription.java:330)
        at com.beust.jcommander.ParameterDescription.addValue(ParameterDescription.java:233)
        at com.beust.jcommander.JCommander.processFixedArity(JCommander.java:895)
        at com.beust.jcommander.JCommander.processFixedArity(JCommander.java:870)
        at com.beust.jcommander.JCommander.parseValues(JCommander.java:721)
        at com.beust.jcommander.JCommander.parse(JCommander.java:340)
        at com.beust.jcommander.JCommander.parse(JCommander.java:319)
        at com.beust.jcommander.JCommander.<init>(JCommander.java:253)
        at com.liferay.damascus.cli.Damascus.run(Damascus.java:57)
        at com.liferay.damascus.cli.Damascus.main(Damascus.java:46)

I fixed it by using JCommander 1.71 (https://github.com/cbeust/jcommander/releases/tag/1.71)

-compile 'com.beust:jcommander:1.64'
+compile 'com.beust:jcommander:1.71'

Is there a reason why you rolled back to version 1.64 in commit bc62708#diff-c197962302397baf3a4cc36463dce5ea?

Feature request: custom json objects in CustomValue or (better) customfield in fields definition

Hi,
great work here! I tried to customize templates to allow generation of an HTML Select input for one of my fields. Currently I added a bunch of fields in the customValue field of base.json. Currently they are:

"fieldXY": 3,
"fieldXYvalue1": "1",
"fieldXYlabel1" : "Option 1",
"fieldXYvalue2": "2",
"fieldXYlabel2" : "Option 2",
"fieldXYvalue3": "3",
"fieldXYlabel3" : "Option 3"

that I parse in the template as

<#if (field.type?string == "com.liferay.damascus.cli.json.fields.Integer" && application.customValue[field.name]?? ) >
  <aui:select name="${field.name}" disabled="false" label='<%=LanguageUtil.get(request, "${lowercaseModel}-${field.name?lower_case}") + requiredLabel%>'>
    <aui:option value="" label="Select a value"/>
    <#list 1..application.customValue[field.name]?number as optionIdx>
      <#assign optionvalue = application.customValue[field.name+"value"+optionIdx?string] />
      <#assign optionlabel = application.customValue[field.name+"label"+optionIdx?string] />
      <aui:option value="${optionvalue}" label="${optionlabel}"/>
    </#list>
  </aui:select>
</#if>

I saw that customValue is implemented as a Map<String, String> so it is a sort of key-value map. Maybe a Map<String, Object> could be better for having custom objects in base.json that can be used in templates.
So in base.json it could be:

"customValue" : {
       "fieldXY": {
            "items": [
                {value:1, label: "Option 1"},
                {value:2, label: "Option 2"},
                {value:3, label: "Option 3"}
          ]
         }
      }

Even better could be having a custom object in the field definition so that one can specify custom code based on field data.
So for an integer field in base.json it could be:

{
  "type": "com.liferay.damascus.cli.json.fields.Integer",
  "name": "fieldXY",
  "title": "Field Title",
  "required": "true" {
  "items": [
     {value:1, label: "Option 1"},
     {value:2, label: "Option 2"},
     {value:3, label: "Option 3"}
    ]
}

edit.jsp's categories, assets and related assets markup need to be updated

The current code is as below

<aui:input name="categories" type="assetCategories" />
<aui:input name="tags" type="assetTags" />

<liferay-ui:panel defaultState="closed" extended="<%=false%>"
    id="todoEntryAssetLinksPanel" persistState="<%=true%>"
    title="related-assets">
    <aui:fieldset>
        <liferay-ui:input-asset-links
            className="<%=Todo.class.getName()%>"
            classPK="<%=todo.getPrimaryKey()%>" />
    </aui:fieldset>
</liferay-ui:panel>

These need to be as follows

<aui:fieldset collapsed="<%= true %>" collapsible="<%= true %>" label="categorization">
    <aui:input name="categories" type="assetCategories" />

    <aui:input name="tags" type="assetTags" />
</aui:fieldset>

<aui:fieldset collapsed="<%= true %>" collapsible="<%= true %>" label="related-assets">
    <liferay-ui:input-asset-links
        className="<%= BlogsEntry.class.getName() %>"
        classPK="<%= entryId %>"
    />
</aui:fieldset>

Add more flexibility to the project name

The project name has 2 restrictions as below now

  1. The project name must start from a capital alphabet letter
  2. Hyphens are not allowed.

1 should be straight forward to resolve, but in terms of 2, service builder doesn't allow hyphens for the model / field name. Damascus utilize project name (a parameter after -init) for model / primary key field name for now, so they may need to be converted into other way, say camel case for example when a user run damascus -init

Advanced Search

Create "Advanced Search" Functionality.

We already created this for 7.0 version, we need to customise so it support 7.1 version.

Generate code for multiple entities in the same modules.

For now, when we define several entities in our base.json file, we get 3 modules for each entity (*-api, *-service and *-web).

In my point of view, it would be more valuable to get 3 modules in total.

To be more concrete, consider the airline example project with entites Flight and Plane.
With the current version of Damascus, the directory layout looks like this (and there is only 1 entity in each service.xml file) :

airline
|
|----Flight-api
|
|----Flight-service
|    |
|    |--- service.xml 
|
|----Flight-web
|
|----Plane-api
|
|----Plane-service
|    |
|    |--- service.xml
|
|----Plane-web

With the proposed evolution, the directory layout would look like that (and all the entities would be in the only service.xml file) :

airline
|
|----airline-api
|
|----airline-service
|    |
|    |--- service.xml
|
|----airline-web

@yasuflatland-lf : What is your feeling about that? If you agree I can implement this evolution and submit you a pull request.

View Detail

Create "View Detail" Functionality.

We already created this for 7.0 version, we need to customise so it support 7.1 version. Our team will upgrade it to 7.1 version, then will ask for pull request.

Add Liferay minimal required versions to the readme file

Since the last release, it seems that the minimal required versions of Liferay for generated code was higher than previously (now it seems to be Liferay 7.0 CE GA4 and Liferay DXP SP3).

It will be very valuable to add the minimal required versions to the readme file.

Preference values can't be referred in view.jsp

need to add something like as follows in *Portlet.java

	@Override
	protected void doDispatch(
			RenderRequest renderRequest, RenderResponse renderResponse)
		throws IOException, PortletException {

        renderRequest.setAttribute(DummyFactoryConfiguration.class.getName(), _dummyFactoryConfiguration);

		super.doDispatch(renderRequest, renderResponse);
	}

*-web switch

*-web switch would be preferable to be implemented when a user needs only services.

README for *-service and *-web

Since many functionalities are pre implemented in the templates, README that described details in *-service and *-web will be helpful for users.

Manage Relations between Entities

1st of all this is a great CRUD plugin for Liferay. Thanks for developing and contributing this.

This feature would be a great benefit : manage relations between entities.

Let us know how we could contribute for Damascus...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.