MyAction template
<webwork1 key="actions" name="MyActions"> <actions> <action name="com.edsd.jira.plugins.simpleplugin.action.MyAction" alias="action" roles-required="admin"> <view name="success">/myaction/success.vm</view> </action> </actions> </webwork1>
<web-section key="my_section" name="MySection" location="atl.jira.proj.config" weight="50"/> <web-item key="my_item_link" name="MyTab" section="atl.jira.proj.config/my_section" weight="10"> <label key="MyLink" /> <link linkId="my_item_link">/secure/action.jspa</link> </web-item>
public class MyAction extends JiraWebActionSupport { private Project project; @Override public String execute() throws Exception { project = getSelectedProjectObject(); // request.setAttribute("com.atlassian.jira.projectconfig.util.ServletRequestProjectConfigRequestCache:project", project); return super.execute(); } }
<web-resource key="my-resources"> <dependency>com.atlassian.jira.jira-project-config-plugin:project-config-global</dependency> <context>my-resources</context> </web-resource>
<!DOCTYPE HTML> <html> <head> <title>MyTestPage</title> <meta name="decorator" content="atl.admin"/> <meta name="projectKey" content="$project.getKey()"/> <meta name="projectId" content="$project.getId()"/> <meta name="admin.active.tab" content="my_item_link"/> <meta name="admin.active.section" content="atl.jira.proj.config"/> $webResourceManager.requireResourcesForContext("my-resources") </head> <body> MyAction template </body> </html>
public interface Student { public void setName(String name); public String getName(); }
import java.util.Date; import net.java.ao.Entity; public interface StudentEntity extends Entity, Student { public Date getCreated(); public void setCreated(Date created); }
<component-import key="ao" name="Active Objects service" interface="com.atlassian.activeobjects.external.ActiveObjects"> <description>Component to access Active Objects functionality from the plugin</description> </component-import> <ao key="ao-module"> <entity>com.edsd.jira.plugins.simpleplugin.entity.StudentEntity</entity> </ao>
public interface StudentDAO { public StudentEntity addStudent(Student student) throws Exception; public StudentEntity[] getStudents() throws Exception; } DAO.Impl StudentDAOImpl. public class StudentDAOImpl implements StudentDAO { private final ActiveObjects ao; public StudentDAOImpl(ActiveObjects ao) { this.ao = ao; } @Override public StudentEntity addStudent(final Student student) throws Exception { return ao.executeInTransaction(new TransactionCallback<StudentEntity>() { @Override public StudentEntity doInTransaction() { StudentEntity entity = ao.create(StudentEntity.class); entity.setName(student.getName()); entity.setCreated(new Date(System.currentTimeMillis())); entity.save(); return entity; } }); } @Override public StudentEntity[] getStudents() throws Exception { return ao.executeInTransaction(new TransactionCallback<StudentEntity[]>() { @Override public StudentEntity[] doInTransaction() { return ao.find(StudentEntity.class); } }); } }
public class DAOFactory { private static StudentDAO studentDAO = null; private static DAOFactory instance = null; private static ActiveObjects ao; public DAOFactory(ActiveObjects ao) { DAOFactory.ao = ao; } public static synchronized DAOFactory getInstance() { if (instance == null) { instance = new DAOFactory(ao); } return instance; } public StudentDAO getStudentDAO() { if (studentDAO == null) { studentDAO = new StudentDAOImpl(ao); } return studentDAO; } }
<component key="dao-factory" class="com.edsd.jira.plugins.simpleplugin.DAO.DAOFactory"> </component>
public class MyAction extends JiraWebActionSupport { private Project project; private StudentEntity[] students; @Override public String execute() throws Exception { project = getSelectedProjectObject(); request.setAttribute("com.atlassian.jira.projectconfig.util.ServletRequestProjectConfigRequestCache:project", project); students = DAOFactory.getInstance().getStudentDAO().getStudents(); return super.execute(); } public String doAdd() throws Exception { String name = request.getParameterValues("name")[0]; Student student = new StudentImpl(name); DAOFactory.getInstance().getStudentDAO().addStudent(student); ServletActionContext.getResponse().sendRedirect("/secure/action.jspa"); return NONE; } }
<body> <form action="/secure/action!add.jspa"> <input type="text" name="name"/> <input type="submit" value="OK"/> </form> <table> <thead> <th>id</th> <th>name</th> <th>created</th> </thead> <tbody> #foreach($student in $students) <tr> <td>$student.getID()</td> <td>$student.getName()</td> <td>$student.getCreated()</td> </tr> #end </tbody> </table> </body>
Source: https://habr.com/ru/post/256789/
All Articles