提交 d76ae74b 编写于 作者: N nilspreusker

added commenting to cycle, added new cycleCommentService to cycle api, fixed...

added commenting to cycle, added new cycleCommentService to cycle api, fixed mapping for comments entity
上级 7fbff404
......@@ -237,12 +237,12 @@ public class CycleDaoMyBatisImpl extends AbstractCycleDaoMyBatisImpl implements
}
@SuppressWarnings("unchecked")
public List<RepositoryNodeCommentEntity> getCommentsForNode(String connectorId, String artifactId) {
public List<RepositoryNodeCommentEntity> getCommentsForNode(String connectorId, String nodeId) {
SqlSession session = openSession();
try {
HashMap<String, Object> parameters = new HashMap<String, Object>();
parameters.put("connectorId", connectorId);
parameters.put("artifactId", artifactId);
parameters.put("nodeId", nodeId);
return session.selectList("selectCycleCommentForSourceArtifact", parameters);
} finally {
......
package org.activiti.cycle.impl.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.activiti.cycle.RepositoryNodeComment;
import org.activiti.cycle.impl.db.CycleTagDao;
import org.activiti.cycle.impl.db.entity.RepositoryNodeCommentEntity;
import org.activiti.cycle.service.CycleCommentService;
/**
*
*
* @author Nils Preusker (nils.preusker@camunda.com)
*/
public class CycleCommentServiceImpl implements CycleCommentService {
private CycleTagDao tagDao;
private CycleServiceConfiguration cycleServiceConfiguration;
public CycleCommentServiceImpl() {
}
public void setCycleServiceConfiguration(CycleServiceConfiguration cycleServiceConfiguration) {
this.cycleServiceConfiguration = cycleServiceConfiguration;
}
public void setTagDao(CycleTagDao tagDao) {
this.tagDao = tagDao;
}
/**
* perform initialization after dependencies are set.
*/
public void initialize() {
// perform initialization
}
public void deleteComment(String id) {
// TODO: the comment related methods should be moved to a dedicated
// commentDao
this.tagDao.deleteComment(id);
}
public List<RepositoryNodeComment> getCommentsForNode(String connectorId, String artifactId) {
// TODO: the comment related methods should be moved to a dedicated
// commentDao
List<RepositoryNodeComment> comments = new ArrayList<RepositoryNodeComment>();
for (RepositoryNodeComment comment : this.tagDao.getCommentsForNode(connectorId, artifactId)) {
comments.add(comment);
}
return comments;
}
public void insertComment(String connectorId, String nodeId, String elementId, String content, String author, Date date, String answeredCommentId) {
// TODO: the comment related methods should be moved to a dedicated
// commentDao
RepositoryNodeCommentEntity comment = new RepositoryNodeCommentEntity();
comment.setId(UUID.randomUUID().toString());
comment.setConnectorId(connectorId);
comment.setNodeId(nodeId);
comment.setElementId(elementId);
comment.setContent(content);
comment.setAuthor(author);
comment.setDate(date);
comment.setAnsweredCommentId(answeredCommentId);
this.tagDao.insertComment(comment);
}
}
......@@ -17,6 +17,8 @@ public class CycleServiceConfiguration {
private CycleRepositoryServiceImpl repositoryService;
private CycleTagServiceImpl tagService;
private CycleCommentServiceImpl commentService;
private CycleConfigurationServiceImpl configurationService;
......@@ -35,6 +37,7 @@ public class CycleServiceConfiguration {
repositoryService = new CycleRepositoryServiceImpl();
configurationService = new CycleConfigurationServiceImpl();
tagService = new CycleTagServiceImpl();
commentService = new CycleCommentServiceImpl();
cyclePluginServiceImpl = new CyclePluginServiceImpl();
cycleContentServiceImpl = new CycleContentServiceImpl();
......@@ -42,6 +45,7 @@ public class CycleServiceConfiguration {
repositoryService.setLinkDao(dao);
configurationService.setCycleConfigurationDao(dao);
tagService.setTagDao(dao);
commentService.setTagDao(dao);
repositoryService.setCycleServiceConfiguration(this);
tagService.setCycleServiceConfiguration(this);
configurationService.setCycleServiceConfiguration(this);
......@@ -50,6 +54,7 @@ public class CycleServiceConfiguration {
private void initializeServices() {
// initialize
tagService.initialize();
commentService.initialize();
repositoryService.initialize();
configurationService.initialize();
}
......@@ -58,6 +63,10 @@ public class CycleServiceConfiguration {
return tagService;
}
public CycleCommentServiceImpl getCommentService() {
return commentService;
}
public CycleRepositoryService getRepositoryService() {
return repositoryService;
}
......
/* 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.activiti.cycle.service;
import java.util.Date;
import java.util.List;
import org.activiti.cycle.RepositoryNodeComment;
public interface CycleCommentService {
public void insertComment(String connectorId, String nodeId, String elementId, String content, String author, Date date, String answeredCommentId);
public void deleteComment(String id);
public List<RepositoryNodeComment> getCommentsForNode(String connectorId, String artifactId);
}
......@@ -41,5 +41,9 @@ public class CycleServiceFactory {
public static CycleContentService getContentService() {
return CycleServiceConfiguration.getInstance().getCycleContentServiceImpl();
}
public static CycleCommentService getCommentService() {
return CycleServiceConfiguration.getInstance().getCommentService();
}
}
......@@ -47,9 +47,9 @@ create table ACT_CY_TAG (
create table ACT_CY_COMMENT (
ID_ varchar NOT NULL,
CONNECTOR_ID_ varchar NOT NULL,
ARTIFACT_ID_ varchar NOT NULL,
NODE_ID_ varchar NOT NULL,
ELEMENT_ID_ varchar DEFAULT NULL,
CONENT_ varchar NOT NULL,
CONTENT_ varchar NOT NULL,
AUTHOR_ varchar,
DATE_ timestamp NOT NULL,
ANSWERED_COMMENT_ID_ varchar DEFAULT NULL,
......
......@@ -47,9 +47,9 @@ create table ACT_CY_TAG (
create table ACT_CY_COMMENT (
ID_ varchar(255) NOT NULL,
CONNECTOR_ID_ varchar(255) NOT NULL,
ARTIFACT_ID_ varchar(550) NOT NULL,
NODE_ID_ varchar(550) NOT NULL,
ELEMENT_ID_ varchar(255) DEFAULT NULL,
CONENT_ text NOT NULL,
CONTENT_ text NOT NULL,
AUTHOR_ varchar(255),
DATE_ timestamp NOT NULL,
ANSWERED_COMMENT_ID_ varchar(255) DEFAULT NULL,
......
......@@ -47,9 +47,9 @@ create table ACT_CY_TAG (
create table ACT_CY_COMMENT (
ID_ NVARCHAR2(255) NOT NULL,
CONNECTOR_ID_ NVARCHAR2(255) NOT NULL,
ARTIFACT_ID_ NVARCHAR2(550) NOT NULL,
NODE_ID_ NVARCHAR2(550) NOT NULL,
ELEMENT_ID_ NVARCHAR2(255) DEFAULT NULL,
CONENT_ NVARCHAR2(2000) NOT NULL,
CONTENT_ NVARCHAR2(2000) NOT NULL,
AUTHOR_ NVARCHAR2(255),
DATE_ TIMESTAMP(6) NOT NULL,
ANSWERED_COMMENT_ID_ NVARCHAR2(255) DEFAULT NULL,
......
......@@ -47,9 +47,9 @@ create table ACT_CY_TAG (
create table ACT_CY_COMMENT (
ID_ varchar(255) NOT NULL,
CONNECTOR_ID_ varchar(255) NOT NULL,
ARTIFACT_ID_ varchar(550) NOT NULL,
NODE_ID_ varchar(550) NOT NULL,
ELEMENT_ID_ varchar(255) DEFAULT NULL,
CONENT_ varchar(5000) NOT NULL,
CONTENT_ varchar(5000) NOT NULL,
AUTHOR_ varchar(255),
DATE_ timestamp NOT NULL,
ANSWERED_COMMENT_ID_ varchar(255) DEFAULT NULL,
......
......@@ -21,8 +21,8 @@
<select id="selectCycleCommentForSourceArtifact" parameterType="map" resultType="list" resultMap="resultMapCycleComment">
select * from ACT_CY_COMMENT
where SOURCE_CONNECTOR_ID_ = #{connectorId} and SOURCE_ARTIFACT_ID_ = #{artifactId}
order DATE_ ASC
where CONNECTOR_ID_ = #{connectorId} and NODE_ID_ = #{nodeId}
order by DATE_ ASC
</select>
<delete id="deleteCycleCommentById" parameterType="string">
......
package org.activiti.cycle.impl.db.impl;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.activiti.cycle.impl.CycleTagContentImpl;
import org.activiti.cycle.impl.db.entity.RepositoryArtifactLinkEntity;
import org.activiti.cycle.impl.db.entity.RepositoryNodeCommentEntity;
import org.activiti.cycle.impl.db.entity.RepositoryNodePeopleLinkEntity;
import org.activiti.cycle.impl.db.entity.RepositoryNodeTagEntity;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
......@@ -166,7 +169,19 @@ public class CycleDaoMyBatisImplTest extends PluggableActivitiTestCase {
}
public void testComment() {
RepositoryNodeCommentEntity comment = new RepositoryNodeCommentEntity();
String id = UUID.randomUUID().toString();
comment.setId(id);
comment.setAuthor("Me");
comment.setConnectorId("testConnectorId");
comment.setNodeId("testNodeId");
comment.setContent("Test Comment...");
comment.setDate(new Date());
comment.setElementId("");
dao.insertComment(comment);
assertEquals(1, dao.getCommentsForNode("testConnectorId", "testNodeId").size());
dao.deleteComment(id);
assertEquals(0, dao.getCommentsForNode("testConnectorId", "testNodeId").size());
}
}
......@@ -66,3 +66,32 @@
background: #666;
color: #fff;
}
#Activiti div .comments {
margin-top: 20px;
}
#Activiti div.comment {
width: 50%;
margin-bottom: 6px;
border-bottom: 4px solid transparent;
}
#Activiti div.comment:hover {
background: #EEE;
border-bottom: 4px solid #AAA;
}
#Activiti span.comment-content {
display: block;
}
#Activiti span.comment-author, #Activiti span.comment-date {
color:#999999;
font-style:italic;
margin-right: 7px;
}
#Activiti textarea#comment-input {
width: 50%;
}
\ No newline at end of file
......@@ -24,7 +24,21 @@
// Listen for events that interest this component
this.onEvent(Activiti.event.updateArtifactView, this.onUpdateArtifactView);
this.onEvent(Activiti.event.clickFormEventButton, this.onClickFormEventButton);
this.waitDialog =
new YAHOO.widget.Panel("wait",
{ width:"200px",
fixedcenter:true,
close:false,
draggable:false,
zindex:4,
modal:true,
visible:false
}
);
this.waitDialog.setBody('<div id="action-waiting-dialog"/>');
this.waitDialog.render(document.body);
this._tabView = {};
this._connectorId = "";
this._repositoryNodeId = "";
......@@ -115,6 +129,11 @@
// Update the heading that displays the name of the selected node
headerEl.id = "header-" + eventValue.repositoryNodeId;
headerEl.innerHTML = eventValue.name;
// Remove the comments
var commentsDiv = YAHOO.util.Dom.get(this.id + '-comments');
if(commentsDiv) {
commentsDiv.innerHTML = '';
}
}
},
......@@ -224,6 +243,9 @@
var optionsMenu = new YAHOO.widget.Button({ type: "menu", label: "Actions", name: "options", menu: actionsMenuItems, container: optionsDiv });
}
optionsDiv.setAttribute('class', 'active');
this.services.repositoryService.loadComments({connectorId: this._connectorId, nodeId: this._repositoryNodeId});
},
onLoadTabSuccess: function Artifact_onLoadTabSuccess(tab, response) {
......@@ -268,6 +290,66 @@
Activiti.widget.PopupManager.displayError(responseJson.message);
},
onLoadCommentsSuccess: function Artifact_onLoadCommentSuccess(response, obj) {
var commentsDiv = YAHOO.util.Dom.get(this.id + '-comments');
if(commentsDiv) {
commentsDiv.innerHTML = '';
} else {
commentsDiv = document.createElement('div');
}
if(response.json.authenticationError) {
return new Activiti.component.AuthenticationDialog(this.id, response.json.repoInError, response.json.authenticationError);
}
// Retrieve rest api response
var commentsJson = response.json;
var artifactEl = document.getElementById("artifact-div");
commentsDiv.setAttribute('class', 'comments');
commentsDiv.setAttribute('id', this.id + '-comments');
commentsDiv.innerHTML += "<h2>Comments</h2>"
for(var item in commentsJson) {
commentsDiv.innerHTML += '<div class="comment"><span class="comment-author">' + commentsJson[item].RepositoryNodeComment.author + '</span><span class="comment-date">' + commentsJson[item].RepositoryNodeComment.creationDate + '</span><span class="comment-content">' + decodeURIComponent(commentsJson[item].RepositoryNodeComment.content) + '</span></div>';
}
commentsDiv.innerHTML += '<form><textarea id="comment-input" name="comment" value=""></textarea></form><span id="addCommentButton" class="yui-button"><span class="first-child"><button type="button">Add Comment</button></span></span>';
artifactEl.appendChild(commentsDiv);
var addCommentButton = new YAHOO.widget.Button("addCommentButton", { label:"Add comment", id:"addCommentButton" });
addCommentButton.addListener("click", this.onClickAddCommentButton, null, this);
this.waitDialog.hide();
},
/**
* Click event listener for the "Add Comment" button.
*
* @param event {object} The event that was triggered
* @param args {Array} The event values
*/
onClickAddCommentButton: function Links_onClickAddLinkButton(event, args)
{
var comment = YAHOO.util.Dom.get("comment-input");
if(comment.value) {
this.waitDialog.show();
this.services.repositoryService.saveComment({connectorId: this._connectorId, nodeId: this._repositoryNodeId, content: encodeURIComponent(comment.value)});
}
},
onSaveCommentSuccess: function Artifact_onSaveCommentSuccess(response, obj)
{
this.services.repositoryService.loadComments({connectorId: this._connectorId, nodeId: this._repositoryNodeId});
// TODO: i18n
Activiti.widget.PopupManager.displayMessage({
text: 'Successfully added comment'
});
},
onExecuteActionClick: function Artifact_onExecuteActionClick(e)
{
return new Activiti.widget.ExecuteArtifactActionForm(this.id + "-executeArtifactActionForm", this.value.connectorId, this.value.artifactId, this.value.actionName);
......
......@@ -70,6 +70,7 @@ h1 {
#Activiti #tags-div a:hover {
color:#666;
text-decoration: underline;
}
#Activiti #tags-div .yui-ac-content {
......
......@@ -251,6 +251,22 @@
saveRepositoryConnectorConfiguration: function RepositoryService_saveRepositoryConnectorConfiguration(configuration) {
this.jsonPost(Activiti.service.REST_PROXY_URI_RELATIVE + "user-config", configuration, null, "saveRepositoryConnectorConfiguration");
},
// {connectorId: "...", nodeId: "..."}
loadComments: function RepositoryService_loadComments(obj) {
this.jsonGet(this.loadCommentsURL(obj), null, "loadComments");
},
loadCommentsURL: function RepositoryService_loadCommentsURL(obj) {
var url = Activiti.service.REST_PROXY_URI_RELATIVE + "comment",
params = Activiti.util.objectToArgumentString(obj);
return (params) ? url + "?" + params : url;
},
// {connectorId: "...", nodeId: "...", content: "..."}
saveComment: function RepositoryService_saveComment(obj) {
this.jsonPost(Activiti.service.REST_PROXY_URI_RELATIVE + "comment", obj, null, "saveComment");
}
});
......@@ -290,8 +306,7 @@
this.service = new Activiti.service.RepositoryService(this);
this.service.setCallback("loadArtifactActionForm", { fn: this.onLoadFormSuccess, scope: this }, {fn: this.onLoadFormFailure, scope: this });
this.service.loadArtifactActionForm(this.connectorId, this.artifactId, this.artifactActionName);
// Initialize the temporary Panel to display while waiting for external content to load
this.waitDialog =
new YAHOO.widget.Panel("wait",
{ width:"200px",
......
......@@ -16,6 +16,7 @@ package org.activiti.rest.api.cycle;
import java.util.Map;
import org.activiti.cycle.RepositoryAuthenticationException;
import org.activiti.cycle.service.CycleCommentService;
import org.activiti.cycle.service.CycleConfigurationService;
import org.activiti.cycle.service.CycleContentService;
import org.activiti.cycle.service.CyclePluginService;
......@@ -35,6 +36,7 @@ public abstract class ActivitiCycleWebScript extends ActivitiWebScript {
protected CycleRepositoryService repositoryService;
protected CycleTagService tagService;
protected CycleCommentService commentService;
protected CycleConfigurationService configurationService;
protected CycleContentService contentService;
protected CyclePluginService pluginService;
......@@ -43,6 +45,7 @@ public abstract class ActivitiCycleWebScript extends ActivitiWebScript {
configurationService = CycleServiceFactory.getConfigurationService();
repositoryService = CycleServiceFactory.getRepositoryService();
tagService = CycleServiceFactory.getTagService();
commentService = CycleServiceFactory.getCommentService();
contentService = CycleServiceFactory.getContentService();
pluginService = CycleServiceFactory.getCyclePluginService();
}
......
/* 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.activiti.rest.api.cycle;
import java.util.Map;
import org.activiti.rest.util.ActivitiRequest;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
/**
* @author Nils Preusker (nils.preusker@camunda.com)
*/
public class CommentDelete extends ActivitiCycleWebScript {
@Override
void execute(ActivitiRequest req, Status status, Cache cache, Map<String, Object> model) {
String id = req.getMandatoryString("id");
commentService.deleteComment(id);
}
}
/* 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.activiti.rest.api.cycle;
import java.util.Map;
import org.activiti.rest.util.ActivitiRequest;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
/**
* @author Nils Preusker (nils.preusker@camunda.com)
*/
public class CommentGet extends ActivitiCycleWebScript {
@Override
void execute(ActivitiRequest req, Status status, Cache cache, Map<String, Object> model) {
String connectorId = req.getMandatoryString("connectorId");
String nodeId = req.getString("nodeId");
model.put("comments", this.commentService.getCommentsForNode(connectorId, nodeId));
}
}
/* 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.activiti.rest.api.cycle;
import java.util.Date;
import java.util.Map;
import org.activiti.rest.util.ActivitiRequest;
import org.activiti.rest.util.ActivitiRequestObject;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
/**
* @author Nils Preusker (nils.preusker@camunda.com)
*/
public class CommentPost extends ActivitiCycleWebScript {
@Override
void execute(ActivitiRequest req, Status status, Cache cache, Map<String, Object> model) {
ActivitiRequestObject obj = req.getBody();
String connectorId = req.getMandatoryString(obj, "connectorId");
String nodeId = req.getMandatoryString(obj, "nodeId");
String content = req.getMandatoryString(obj, "content");
String elementId = req.getString("elementId");
String answeredCommentId = req.getString("answeredCommentId");
String author = req.getCurrentUserId();
Date date = new Date();
this.commentService.insertComment(connectorId, nodeId, elementId, content, author, date, answeredCommentId);
}
}
<webscript>
<shortname>Delete a cycle repository node comment</shortname>
<description>Deletes the cycle repository node comment identified by the comment id.</description>
<url>/comment</url>
<authentication>user</authentication>
<format default="json">argument</format>
</webscript>
\ No newline at end of file
<#if authenticationException??>
<#import "cycle.lib.ftl" as cycleLib/>
<@cycleLib.printAuthenticationException authenticationException/>
<#else>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"success": "true"
}
</#escape>
</#if>
\ No newline at end of file
<webscript>
<shortname>Comment</shortname>
<description>Returns a json representation of a cycle repository artifact comment.</description>
<url>/comment?connectorId={connectorId}&amp;artifactId={artifactId}</url>
<authentication>user</authentication>
<format default="json">argument</format>
</webscript>
\ No newline at end of file
[
<#list comments as comment>{
"RepositoryNodeComment": {
<#escape x as jsonUtils.encodeJSONString(x)>
"id": "${comment.id!''}",
"connectorId": "${comment.connectorId!''}",
"nodeId": "${comment.nodeId!''}",
"elementId": "${comment.elementId!''}",
"content": "${comment.content!''}",
"author": "${comment.author!''}",
"answeredCommentId": "${comment.answeredCommentId!''}",
</#escape>
"creationDate": "${comment.date?datetime}"
}
}<#if comment_has_next>,</#if></#list>
]
\ No newline at end of file
<webscript>
<shortname>Create a cycle repository node comment</shortname>
<description>Creates a cycle repository node comment and writes it to the database.</description>
<url>/comment</url>
<authentication>user</authentication>
<format default="json">argument</format>
</webscript>
\ No newline at end of file
<#if authenticationException??>
<#import "cycle.lib.ftl" as cycleLib/>
<@cycleLib.printAuthenticationException authenticationException/>
<#else>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"success": "true"
}
</#escape>
</#if>
\ No newline at end of file
......@@ -394,4 +394,19 @@
class="org.activiti.rest.api.cycle.AvailableConnectorConfigsGet"
parent="activitiWebScript">
</bean>
<bean id="webscript.org.activiti.rest.api.cycle.comment.post"
class="org.activiti.rest.api.cycle.CommentPost"
parent="activitiWebScript">
</bean>
<bean id="webscript.org.activiti.rest.api.cycle.comment.get"
class="org.activiti.rest.api.cycle.CommentGet"
parent="activitiWebScript">
</bean>
<bean id="webscript.org.activiti.rest.api.cycle.comment.delete"
class="org.activiti.rest.api.cycle.CommentDelete"
parent="activitiWebScript">
</bean>
</beans>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册