Skip to content

Commit

Permalink
add cola framework components
Browse files Browse the repository at this point in the history
  • Loading branch information
fulan.zjf committed Jul 1, 2020
1 parent d932286 commit e15e8af
Show file tree
Hide file tree
Showing 93 changed files with 3,204 additions and 0 deletions.
134 changes: 134 additions & 0 deletions cola-framework-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.aliyun</groupId>
<artifactId>cola-common</artifactId>
<packaging>jar</packaging>
<version>3.0.0</version>

<name>cola common</name>
<url>https://github.com/alibaba/COLA</url>
<description>Cola framework common components</description>

<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<licenses>
<license>
<name>GNU Lesser General Public License v2.1</name>
<url>https://github.com/alibaba/COLA/blob/master/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<connection>scm:git:https://github.com/alibaba/COLA.git</connection>
<developerConnection>scm:git:https://github.com/alibaba/COLA.git</developerConnection>
<url>https://github.com/alibaba/COLA</url>
</scm>

<developers>
<developer>
<id>Frank</id>
<name>Frank Zhang</name>
<email>25216348@qq.com</email>
</developer>
</developers>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<encoding>UTF-8</encoding>
<doclint>none</doclint>
</configuration>
</plugin>
<!-- This is for central repository, comment it when build at local-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.alibaba.cola.dto;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
* This is the object communicate with Client.
* The clients could be view layer or other HSF Consumers
* @author fulan.zjf 2017-10-27 PM 12:19:15
*/
public abstract class ClientObject implements Serializable{

private static final long serialVersionUID = 1L;

/**
* This is for extended values
*/
protected Map<String, Object> extValues = new HashMap<String, Object>();

public Object getExtField(String key){
if(extValues != null){
return extValues.get(key);
}
return null;
}

public void putExtField(String fieldName, Object value){
this.extValues.put(fieldName, value);
}

public Map<String, Object> getExtValues() {
return extValues;
}

public void setExtValues(Map<String, Object> extValues) {
this.extValues = extValues;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.alibaba.cola.dto;

import com.alibaba.cola.extension.BizScenario;

/**
* Command stands for a request from Client.
* According CommandExecutor will help to handle the business logic. This is a classic Command Pattern
*
* @author fulan.zjf 2017年10月27日 下午12:28:24
*/
public abstract class Command extends DTO{

private static final long serialVersionUID = 1L;

private BizScenario bizScenario;

public BizScenario getBizScenario() {
return bizScenario;
}

public void setBizScenario(BizScenario bizScenario) {
this.bizScenario = bizScenario;
}
}
16 changes: 16 additions & 0 deletions cola-framework-common/src/main/java/com/alibaba/cola/dto/DTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.alibaba.cola.dto;

import java.io.Serializable;

/**
* Data Transfer object, including Command, Query and Response,
*
* Command and Query is CQRS concept.
*
* @author fulan.zjf 2017年10月21日 下午8:53:55
*/
public abstract class DTO implements Serializable{

private static final long serialVersionUID = 1L;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.alibaba.cola.dto;

/**
* Extends your error codes in your App by implements this Interface.
*
* Created by fulan.zjf on 2017/12/18.
*/
public interface ErrorCodeI {

public String getErrCode();

public String getErrDesc();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.alibaba.cola.dto;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* Response with batch record to return,
* usually use in page query or conditional query
* <p/>
* Created by Danny.Lee on 2017/11/1.
*/
public class MultiResponse<T> extends Response {

private int total;

private Collection<T> data;

public static <T> MultiResponse<T> of(Collection<T> data, int total) {
MultiResponse<T> multiResponse = new MultiResponse<>();
multiResponse.setSuccess(true);
multiResponse.setData(data);
multiResponse.setTotal(total);
return multiResponse;
}

public static <T> MultiResponse<T> ofWithoutTotal(Collection<T> data) {
return of(data,0);
}


public int getTotal() {
return total;
}


public void setTotal(int total) {
this.total = total;
}

public List<T> getData() {
return null == data ? new ArrayList<>() : new ArrayList<>(data);
}


public void setData(Collection<T> data) {
this.data = data;
}

public static MultiResponse buildFailure(String errCode, String errMessage) {
MultiResponse response = new MultiResponse();
response.setSuccess(false);
response.setErrCode(errCode);
response.setErrMessage(errMessage);
return response;
}

public static MultiResponse buildSuccess(){
MultiResponse response = new MultiResponse();
response.setSuccess(true);
return response;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.alibaba.cola.dto;

import java.io.Serializable;

/**
* Order Description
*
* @author Danny.Lee 2017/12/19
*/
public class OrderDesc implements Serializable{

private String col;
private boolean asc = true;

public String getCol() {
return col;
}

public void setCol(String col) {
this.col = col;
}

public boolean isAsc() {
return asc;
}

public void setAsc(boolean asc) {
this.asc = asc;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.alibaba.cola.dto;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* page query
* <p/>
* Created by Danny.Lee on 2017/11/1.
*/
public abstract class PageQuery extends Query {

private int pageNum = 1;
private int pageSize = 10;
private boolean needTotalCount = true;
private List<OrderDesc> orderDescs;

public int getPageNum() {
return pageNum;
}

public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

public boolean isNeedTotalCount() {
return needTotalCount;
}

public void setNeedTotalCount(boolean needTotalCount) {
this.needTotalCount = needTotalCount;
}

public List<OrderDesc> getOrderDescs() {
return orderDescs;
}

public void addOrderDesc(OrderDesc orderDesc) {
if (null == orderDescs) {
orderDescs = new ArrayList<>();
}
orderDescs.add(orderDesc);
}

public int getOffset() {
return pageNum > 0 ? (pageNum - 1) * pageSize : 0;
}
}
Loading

0 comments on commit e15e8af

Please sign in to comment.