orbeon-bluedb-integration/integration-module/src/main/java/hycom/service/DatabaseService.java

134 lines
3.2 KiB
Java

package hycom.service;
import hycom.dao.FormDao;
import hycom.exceptions.DbException;
import hycom.model.Form;
import hycom.model.User;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* Database service
*/
@Service
@Transactional
@RequestMapping("/logger")
public class DatabaseService {
private static final Logger logger = LoggerFactory.getLogger(DatabaseService.class);
@Autowired
private FormDao formDao;
public List<Form> getForms() {
try {
return formDao.getForms();
}
catch (DbException e) {
logger.error("Error in method getForms(): " + e.getMessage());
}
return null;
}
public List<Form> getFormsUsingPagination(int offset, int limit, String fromDate, String toDate, String formNameSearch,
String category, String pillar, String name) {
try {
return formDao.getForms(offset, limit, fromDate, toDate, formNameSearch, category, pillar, name);
}
catch (DbException e) {
logger.error("Error in method getFormsUsingPagination(...): " + e.getMessage());
}
return null;
}
public Long getFormsCount(String fromDate, String toDate, String formNameSearch,
String category, String pillar, String name) {
try {
return formDao.getFormsCount(fromDate, toDate, formNameSearch, category, pillar, name);
}
catch (DbException e) {
logger.error("Error in getFormsCount(...): " + e.getMessage());
}
return null;
}
public List<User> getUsersContainsAttachments() {
try {
return formDao.getUsersContainsAttachments();
}
catch (DbException e) {
logger.error("Error in getUsersContainsAttachments(): " + e.getMessage());
}
return null;
}
public String getAttachments(String userName) {
try {
return formDao.getAttachments(userName);
}
catch (DbException e) {
logger.error("Error in getAttachments(...): " + e.getMessage());
}
return null;
}
public Boolean removeAttachments(String userName) {
try {
formDao.removeAttachments(userName);
return true;
}
catch (DbException e) {
logger.error("Error in removeAttachments(...): " + e.getMessage());
}
return false;
}
public Form getForm(int formId) {
try {
return formDao.getForm(formId);
}
catch (DbException e) {
logger.error("Error in getForm(...): " + e.getMessage());
}
return null;
}
public void submitForm(String id) {
try {
boolean submitted = formDao.isFormSubmitted(id);
if (submitted)
formDao.deleteSubmittedForm(id);
formDao.submitForm(id);
}
catch (DbException e) {
logger.error("Error in submitForm(...): " + e.getMessage());
}
}
public Boolean hasRemovedAttachments(String id) {
try {
return formDao.hasRemovedAttachments(id);
}
catch (DbException e) {
logger.error("Error in hasRemovedAttachments(...): " + e.getMessage());
return null;
}
}
public Boolean isFormSubmitted(String id) {
try {
return formDao.isFormSubmitted(id);
}
catch (DbException e) {
logger.error("isFormSubmitted(...): " + e.getMessage());
return null;
}
}
}