/*
* Copyright (c) 2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.humantask.dao.jpa.openjpa;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.humantask.dao.*;
import org.wso2.carbon.humantask.dao.jpa.openjpa.model.Message;
import org.wso2.carbon.humantask.dao.jpa.openjpa.model.Task;
import org.wso2.carbon.humantask.store.HumanTaskBaseConfiguration;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import java.util.List;
public class HumanTaskDAOImpl implements HumanTaskDAO {
private static final Log log = LogFactory.getLog(HumanTaskDAOImpl.class);
private EntityManager entityManager;
public HumanTaskDAOImpl(EntityManager entityManager) {
this.entityManager = entityManager;
}
public List<TaskDAO> getTasksForUser(String userName) {
return null;
}
public PaginatedResultList<TaskDAO> getPaginatedTaskListForUser(String userName) {
return null;
}
public TaskDAO createTask(HumanTaskBaseConfiguration taskConfiguration, MessageDAO inputMessage) {
EntityTransaction tx = null;
Task task = null;
try {
tx = entityManager.getTransaction();
tx.begin();
if (taskConfiguration.isTask()) {
task = new Task(taskConfiguration.getName(), TaskType.TASK);
} else {
task = new Task(taskConfiguration.getName(), TaskType.NOTIFICATION);
}
entityManager.persist(task);
task.setInputMessage((Message) inputMessage);
// TODO: Set priority after implementing evaluation context
task.setStatus(TaskStatus.CREATED);
task.setSkipable(false);
task.setEscalated(false);
// TODO: Populate generic human roles
// TODO: Populate presnetation elements
// TODO: Nominate owner
tx.commit();
return task;
} catch (RuntimeException re) {
if (tx != null && tx.isActive()) {
tx.rollback();
}
throw re;
}
}
public MessageDAO createMessage() {
return null;
}
}