You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.1 KiB
Java
79 lines
2.1 KiB
Java
package cokr.xit.foundation.component;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
import cokr.xit.foundation.AbstractObject;
|
|
import cokr.xit.foundation.data.DataObject;
|
|
|
|
/**서비스 응답으로 반환하는 정보를 갖는 객체의 베이스 클래스.<br />
|
|
* 서비스 결과로 전달해야할 정보가 여러 개일 경우 이 클래스를 상속받아 응답클래스를 정의한다.<br />
|
|
* 결과 정보가 하나일 경우는 응답클래스를 정의할 필요없다.
|
|
* @author mjkhan
|
|
*/
|
|
public class ServiceResponse extends AbstractObject {
|
|
private List<ExecInfo> results;
|
|
private DataObject info;
|
|
|
|
public List<ExecInfo> getResults() {
|
|
return ifEmpty(results, Collections::emptyList);
|
|
}
|
|
|
|
public ServiceResponse setResults(List<ExecInfo> results) {
|
|
this.results = results;
|
|
return this;
|
|
}
|
|
|
|
public ServiceResponse add(ExecInfo result) {
|
|
if (results == null)
|
|
results = new ArrayList<>();
|
|
else if (!(results instanceof ArrayList)) {
|
|
List<ExecInfo> tmp = results;
|
|
results = new ArrayList<>(tmp);
|
|
}
|
|
|
|
results.add(result);
|
|
|
|
return this;
|
|
}
|
|
|
|
/**응답 추가정보를 반환한다.
|
|
* @return 응답 추가정보
|
|
*/
|
|
public DataObject getInfo() {
|
|
return info;
|
|
}
|
|
|
|
/**응답 추가정보를 초기화 후 반환한다.
|
|
* @return 응답 추가정보
|
|
*/
|
|
private DataObject info() {
|
|
return ifEmpty(info, () -> info = new DataObject());
|
|
}
|
|
|
|
/**주어진 키와 값으로 추가정보를 설정한다.
|
|
* @param <T> 응답 타입
|
|
* @param key 추가정보 키
|
|
* @param val 추가정보
|
|
* @return 현재 응답
|
|
*/
|
|
public ServiceResponse info(String key, Object val) {
|
|
info().put(key, val);
|
|
return this;
|
|
}
|
|
|
|
/**성공한 결과로 저장한 데이터수를 반환한다.
|
|
* @return 성공한 결과로 저장한 데이터수
|
|
*/
|
|
public int getAffected() {
|
|
return ExecInfo.getAffected(results);
|
|
}
|
|
|
|
/**모든 결과가 성공인지 반환한다.
|
|
* @return 모든 결과의 성공 여부
|
|
*/
|
|
public boolean isSuccess() {
|
|
return ExecInfo.isSuccess(results);
|
|
}
|
|
} |