Thursday, 18 June 2015

Stpes to create Maven Project from Eclipse



Please make sure the environment variables M2_HOME, PATH etc are setup. If not, please refer to the other post on how to setup the environment.

1.     Once the environment is setup, eclipse configurations need to be updated for Maven. 

2.     Go to Window -> Preferences -> Maven-> Installations. Click on Add and select
       the Maven installation home directory.

3.     Go to "User settings" Under "Maven" and browse the user settings and global settings 
       point to  the settings.xml that should be present in your <<installation directory>>\conf folder.

4.     Go to File-> New -> select Maven Project.  Select the workspace and click on Next.

5.     It will list down all the archetypes available. Select the appropriate archetype. Let's say we want  to create a quick project select  “maven-archetype-quickstart” archetype from the list and click  on Next

6.     In the Next window enter the following details
a.         Group Id: <<com.sample.app>> //Similar to your package
b.        Artifact Id: <<SampleApp>> //your project name. 
c.         Version: <<0.0.1-SNAPSHOT>> //versioning used for project. 
d.        Package: <<Jar/War>> //when the packaging is done, it will create the Jar/War with   ArtifactId-Version. In our ex: SampleApp-0.0.1-SNAPSHOT.Jar


The above steps should create a project with name SampleApp.




Wednesday, 17 June 2015

Steps to add Custom Attributes in liferay portal


Below are the steps to be followed for adding the custom attributes to the existing resources provided by liferay portal.

1. Login to Liferay Portal with Admin and go to Control Panel

2. Select "Custom Fields"  Under "Configuration" section.

3. It will list down the list of existing resources. select the edit button against the resource
    to which you want to add the custom attribute.

4. Upon select Edit, It will show the resource with the button "Add Custom Field". Click on It.

5. you will be asked to enter Key and Type. Please give the name and datatype of the
    custom attribute to store in. The key is the name with which the custom attribute
    can be accessed further. Click on Save.

6. Upon Save, It will list down the custom attributes added to a particular selected resource.
    It will also display the Key for the attribute.







Steps to create Maven Project from Command line

Below are the steps to be followed for creating a simple Maven project from command line.

1.  Please make sure the enviroment is setup. please see the previous post on how to set up
     the Maven environment.

2. Open command prompt and go to the folder where you want the project to be created
     and type the below command.
       mvn archetype:generate -DgroupId=com.myapp  //Project packaging
      -DartifactId=mavendemo  //Project name
      -DarchetypeArtifactId=maven-archetype-quickstart  //Template
      -DinteractiveMode=false 

  • The above command creates a project mavendemo with the entire project structure based on the "maven-archetype-quickstart" template.
  • It will also download all the required dependencies from the Maven central repository and store it in local repository.
  • All the source code will be put under src/main/java folder and all the test code will be put under src/test/java
  • It will also create pom.xml. It is the Project Object Model which is the fundamental unit of work in Maven. It contains all the project information like plugins, dependencies, directory sturcture, configuration details to build the project.

If you want the project to be imported into eclipse, follow the below steps.

3. go to the project folder where it is created (in our ex: mavendemo folder) and type command
    mvn eclipse:eclipse. This will generate the eclipse related env files like .classpath
    and .project.

4. In eclipse go to File-> Import -> General -> Existing Projects into Workspace.




Tuesday, 16 June 2015

Maven Environment Setup

Below are the steps to be followed for setting up Maven Environment

Step1: Verify Java Installation on your machine.
           Open the command prompt and type java -version. It should return us the Java version
           we are using.

If the JDK is not installed on your machine, get it from Oracle downloads page.

Step2: Set JAVA_HOME env variable to point to the installation directory of Java.
          In windows, open the computer -> properties-> Advanced System Settings ->
          Click on Env variables.
          JAVA_HOME = C:\Program Files\Java\jdk1.8.0_40

Step3: Append the path to the JDK bin directory to the PATH env variable.
          Open the env variables tab, and append C:\Program Files\Java\jdk1.8.0_40\bin to PATH.

Step4: Extract the Maven Archive to the local directory.

Step5: Set the Env variable M2_HOME to the Maven directory
            M2_HOME = D:\apache-maven-3.3.3

Step6: Append Maven bin directory (D:\apache-maven-3.3.3\bin) to the PATH env variable.

Step7: Verify Maven Installation. Open the command prompt and type in mvn --version.
           It should give us the version details.

With this, the maven environment setup is done.
         




How to draw UML Sequence Diagrams in Visio 2013

Below are the steps to draw UML sequence diagram in Viso.

Open the Visio and
-> select the Blank Drawing
-> select the US Units
-> Click on Create
-> Click on More Shapes option in the left pane. It will open the tab to browse the shape categories
-> Go to Software and Database ->Software -> Click on UML Sequence.
     It will open up the stencils for the UML sequence diagram.

Let's say for example if we want to draw the sequence digaram for the interactions between two systems.  Ex: System 1 and System 2.

-> Drag Object Lifeline stencil to the drawing page. Double click on the box and name it System1.
-> Similarly drag another object lifeline stencil to the page and name it System2.
-> Drag the Activation stencis to the System 1 (the vertical line). Drag another to System 2 lifeline.
-> For representing any contact from System 1 to System2 like messages, API calls etc ,drag -> (Arrow) message stencil between two systems. The origin of the arrow should be on System1, Activation line and the Arrow should point to the System 2 Activation lifeline.
-> For the return message, use  <-- (return Arrow with dotted lines) stencil.
-> for any functionality within the system, use Self Message stencil.



Friday, 12 June 2015

How to add or get custom field data in liferay portal using API

Liferay is providing the following remote service com.liferay.portlet.expando.service.impl.ExpandoValueServiceImpl which can be used for adding/selecting/updating the custom field data.

Here are the parameters to be passed in:

1.    CompanyId: company id that is assigned
2.    Class Name: The entity name that we have created the custom attribute for
3.    TableName: Is always CUSTOM_FIELDS
4.    ColumnName: The name given for the attribute
5.    classPK: Primary key value within the entity.
6.    Data: the value to be updated.

For adding or updating a single field, The API is ‘/expandovalue/add-value'.
For adding or updating multiple fields the API is ‘/expandovalue/add-values'.
For getting the data (single or multiple) the API is '/expandovalue/get-data' 

Below are the sample examples - Language is the custom field added.

For Add

Liferay.Service(
  '/expandovalue/add-value',
  {
    companyId: 101233,
    className: 'com.liferay.portal.model.User',
    tableName: 'CUSTOM_FIELDS',
    columnName: 'Language',
    classPK: 10234,
    data: 'English'
  },
  function(obj) {
    console.log(obj);
  }
);

For adding multiple Values (Here Language and Notification Preferences are custom Fields)
Provide the input to attributeValues as Collection object.

Liferay.Service(
  '/expandovalue/add-values',
  {
    companyId: 101233,
    className: 'com.liferay.portal.model.User',
    tableName: 'CUSTOM_FIELDS',
    classPK: 10234,
    attributeValues: {Language:English, Notification Preference:Email}
  },
  function(obj) {
    console.log(obj);
  }
);

For getting the data (In column Names give the multiple values for getting more than one column data)

Liferay.Service(
  '/expandovalue/get-data',
  {
    companyId: 101233,
    className: 'com.liferay.portal.model.User',
    tableName: 'CUSTOM_FIELDS',
    columnNames: Language, Notification Preference,
    classPK: 10234
  },
  function(obj) {
    console.log(obj);
  }
);


Tuesday, 9 June 2015

java.lang.NoClassDefFoundError: org/json/JSONObject

I was getting the above error even after adding the required jar (java-json.jar) to the library.

I have followed the below steps to add this jar to the library.

Click on Project -> Properties -> Java Build Path (on left panel) -> select Libraries Tab -> click on Add External JARs  and import the jar.

So in order to avoid the above problem I add the above jar to Deployment Assembly as well.

Click on Project -> Properties -> Deployment Assembly (on left panel) - > click on Add -> Select Java Build Path Entries -> select the Jar.

Not sure whether it is the good approach or not but it solved my problem.

Another way to avoid these dependency errors is to use Maven.