From af42cb1f00c5d7d73b3eb9b57c372aef45a87d85 Mon Sep 17 00:00:00 2001 From: rekoe <koukou890@qq.com> Date: Fri, 25 Mar 2016 10:27:26 +0800 Subject: [PATCH] clean --- src/main/java/com/rekoe/MvcSetup.java | 2 + .../java/com/rekoe/domain/ProjectConfig.java | 26 ++++ .../com/rekoe/module/facebook/pay/Action.java | 62 --------- .../module/facebook/pay/Application.java | 32 ----- .../rekoe/module/facebook/pay/Dispute.java | 55 -------- .../com/rekoe/module/facebook/pay/Entry.java | 37 ------ .../com/rekoe/module/facebook/pay/Error.java | 15 --- .../rekoe/module/facebook/pay/ErrorInfo.java | 33 ----- .../facebook/pay/FacebookRequestResult.java | 17 --- .../com/rekoe/module/facebook/pay/Items.java | 33 ----- .../com/rekoe/module/facebook/pay/Order.java | 121 ------------------ .../rekoe/module/facebook/pay/PayObject.java | 30 ----- .../module/facebook/pay/PlatformUser.java | 24 ---- .../module/facebook/pay/RefundableAmount.java | 23 ---- .../com/rekoe/service/ProjectService.java | 3 + .../com/rekoe/service/RepositoryService.java | 70 ++++++++++ 16 files changed, 101 insertions(+), 482 deletions(-) delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/Action.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/Application.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/Dispute.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/Entry.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/Error.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/ErrorInfo.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/FacebookRequestResult.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/Items.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/Order.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/PayObject.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/PlatformUser.java delete mode 100644 src/main/java/com/rekoe/module/facebook/pay/RefundableAmount.java diff --git a/src/main/java/com/rekoe/MvcSetup.java b/src/main/java/com/rekoe/MvcSetup.java index 73acdbc..0f7a9c4 100644 --- a/src/main/java/com/rekoe/MvcSetup.java +++ b/src/main/java/com/rekoe/MvcSetup.java @@ -16,6 +16,7 @@ import org.nutz.mvc.Setup; import org.nutz.plugins.view.freemarker.FreeMarkerConfigurer; import com.rekoe.domain.Pj; +import com.rekoe.domain.ProjectConfig; import com.rekoe.domain.User; import com.rekoe.domain.Usr; import com.rekoe.service.UserService; @@ -47,6 +48,7 @@ public class MvcSetup implements Setup { Daos.createTablesInPackage(dao, User.class.getPackage().getName(), false); Daos.migration(dao, Usr.class, true, true, false); Daos.migration(dao, Pj.class, true, true, false); + Daos.migration(dao, ProjectConfig.class, true, true, false); if (0 == dao.count(User.class)) { FileSqlManager fm = new FileSqlManager("init_system_h2.sql"); List<Sql> sqlList = fm.createCombo(fm.keys()); diff --git a/src/main/java/com/rekoe/domain/ProjectConfig.java b/src/main/java/com/rekoe/domain/ProjectConfig.java index 27581a4..eebe69a 100644 --- a/src/main/java/com/rekoe/domain/ProjectConfig.java +++ b/src/main/java/com/rekoe/domain/ProjectConfig.java @@ -1,6 +1,8 @@ package com.rekoe.domain; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import org.nutz.dao.entity.annotation.ColDefine; import org.nutz.dao.entity.annotation.ColType; @@ -12,6 +14,8 @@ import org.nutz.dao.entity.annotation.Name; import org.nutz.dao.entity.annotation.Prev; import org.nutz.dao.entity.annotation.Table; +import com.rekoe.valueadaptor.StringJsonAdaptor; + @Table("project_config") public class ProjectConfig implements Serializable { @@ -32,6 +36,28 @@ public class ProjectConfig implements Serializable { @Default("http://127.0.0.1/") private String domainPath; + @Column("def_dirs") + @ColDefine(type = ColType.VARCHAR, width = 225, adaptor = StringJsonAdaptor.class) + @Default("[server,client,art,design,plan]") + @Comment("默认初始化目录") + private List<String> dirs; + + public List<String> getDirs() { + if (dirs == null) { + this.dirs = new ArrayList<>(); + } + return dirs; + } + + public void setDirs(List<String> dirs) { + this.dirs = dirs; + } + + public ProjectConfig addDir(String dir) { + getDirs().add(dir); + return this; + } + public ProjectConfig() { super(); } diff --git a/src/main/java/com/rekoe/module/facebook/pay/Action.java b/src/main/java/com/rekoe/module/facebook/pay/Action.java deleted file mode 100644 index 0ece3cf..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/Action.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.rekoe.module.facebook.pay; - -import org.nutz.json.JsonField; - -public class Action { - private String type; - private String status; - private String currency; - private String amount; - @JsonField("time_created") - private String timeCreated; - @JsonField("time_updated") - private String timeUpdated; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getCurrency() { - return currency; - } - - public void setCurrency(String currency) { - this.currency = currency; - } - - public String getAmount() { - return amount; - } - - public void setAmount(String amount) { - this.amount = amount; - } - - public String getTimeCreated() { - return timeCreated; - } - - public void setTimeCreated(String timeCreated) { - this.timeCreated = timeCreated; - } - - public String getTimeUpdated() { - return timeUpdated; - } - - public void setTimeUpdated(String timeUpdated) { - this.timeUpdated = timeUpdated; - } -} \ No newline at end of file diff --git a/src/main/java/com/rekoe/module/facebook/pay/Application.java b/src/main/java/com/rekoe/module/facebook/pay/Application.java deleted file mode 100644 index 8ab1c36..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/Application.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.rekoe.module.facebook.pay; - -public class Application { - - private String name; - private String namespace; - private String id; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getNamespace() { - return namespace; - } - - public void setNamespace(String namespace) { - this.namespace = namespace; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/Dispute.java b/src/main/java/com/rekoe/module/facebook/pay/Dispute.java deleted file mode 100644 index 0e57c69..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/Dispute.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.rekoe.module.facebook.pay; - -import org.nutz.json.JsonField; - -public class Dispute { - - @JsonField("user_comment") - private String userComment; - @JsonField("time_created") - private String timeCreated; - @JsonField("user_email") - private String userEmail; - private String status; - private String reason; - - public String getUserComment() { - return userComment; - } - - public void setUserComment(String userComment) { - this.userComment = userComment; - } - - public String getTimeCreated() { - return timeCreated; - } - - public void setTimeCreated(String timeCreated) { - this.timeCreated = timeCreated; - } - - public String getUserEmail() { - return userEmail; - } - - public void setUserEmail(String userEmail) { - this.userEmail = userEmail; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/Entry.java b/src/main/java/com/rekoe/module/facebook/pay/Entry.java deleted file mode 100644 index 4e777cb..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/Entry.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.rekoe.module.facebook.pay; - -import java.util.List; - -import org.nutz.json.JsonField; - -public class Entry { - - private String id; - private long time; - @JsonField("changed_fields") - private List<String> changedFields; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public long getTime() { - return time; - } - - public void setTime(long time) { - this.time = time; - } - - public List<String> getChangedFields() { - return changedFields; - } - - public void setChangedFields(List<String> changedFields) { - this.changedFields = changedFields; - } -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/Error.java b/src/main/java/com/rekoe/module/facebook/pay/Error.java deleted file mode 100644 index f98f02d..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/Error.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.rekoe.module.facebook.pay; - -public class Error { - - private ErrorInfo error; - - public ErrorInfo getError() { - return error; - } - - public void setError(ErrorInfo error) { - this.error = error; - } - -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/ErrorInfo.java b/src/main/java/com/rekoe/module/facebook/pay/ErrorInfo.java deleted file mode 100644 index fb604b7..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/ErrorInfo.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.rekoe.module.facebook.pay; - -public class ErrorInfo { - - private String message; - private String type; - private int code; - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/FacebookRequestResult.java b/src/main/java/com/rekoe/module/facebook/pay/FacebookRequestResult.java deleted file mode 100644 index 7ab155e..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/FacebookRequestResult.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.rekoe.module.facebook.pay; - -import com.restfb.Facebook; - -public class FacebookRequestResult { - - @Facebook - private boolean success; - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/Items.java b/src/main/java/com/rekoe/module/facebook/pay/Items.java deleted file mode 100644 index 1cbdee8..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/Items.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.rekoe.module.facebook.pay; - -public class Items { - - private String type; - private String product; - private int quantity; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getProduct() { - return product; - } - - public void setProduct(String product) { - this.product = product; - } - - public int getQuantity() { - return quantity; - } - - public void setQuantity(int quantity) { - this.quantity = quantity; - } - -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/Order.java b/src/main/java/com/rekoe/module/facebook/pay/Order.java deleted file mode 100644 index 9095b68..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/Order.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.rekoe.module.facebook.pay; - -import java.util.List; - -import org.nutz.json.JsonField; - -public class Order { - - private String id; - private Application application; - private PlatformUser user; - private List<Action> actions; - @JsonField("refundable_amount") - private RefundableAmount refundableAmount; - private String country; - @JsonField("request_id") - private String requestID; - @JsonField("created_time") - private String createdTime; - @JsonField("payout_foreign_exchange_rate") - private int payoutForeignExchangeRate; - private List<Items> items; - private List<Dispute> disputes; - private int test; - - public int getTest() { - return test; - } - - public void setTest(int test) { - this.test = test; - } - - public List<Dispute> getDisputes() { - return disputes; - } - - public void setDisputes(List<Dispute> disputes) { - this.disputes = disputes; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Application getApplication() { - return application; - } - - public void setApplication(Application application) { - this.application = application; - } - - public PlatformUser getUser() { - return user; - } - - public void setUser(PlatformUser user) { - this.user = user; - } - - public List<Action> getActions() { - return actions; - } - - public void setActions(List<Action> actions) { - this.actions = actions; - } - - public RefundableAmount getRefundableAmount() { - return refundableAmount; - } - - public void setRefundableAmount(RefundableAmount refundableAmount) { - this.refundableAmount = refundableAmount; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getRequestID() { - return requestID; - } - - public void setRequestID(String requestID) { - this.requestID = requestID; - } - - public String getCreatedTime() { - return createdTime; - } - - public void setCreatedTime(String createdTime) { - this.createdTime = createdTime; - } - - public int getPayoutForeignExchangeRate() { - return payoutForeignExchangeRate; - } - - public void setPayoutForeignExchangeRate(int payoutForeignExchangeRate) { - this.payoutForeignExchangeRate = payoutForeignExchangeRate; - } - - public List<Items> getItems() { - return items; - } - - public void setItems(List<Items> items) { - this.items = items; - } -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/PayObject.java b/src/main/java/com/rekoe/module/facebook/pay/PayObject.java deleted file mode 100644 index 85ebf71..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/PayObject.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.rekoe.module.facebook.pay; - -import java.util.List; - -import org.nutz.json.JsonField; - -//{"object":"payments","entry":[{"id":"577551589029171","time":1402986080,"changed_fields":["actions"]}]} -public class PayObject { - - private String object; - @JsonField("entry") - private List<Entry> entryList; - - public List<Entry> getEntryList() { - return entryList; - } - - public void setEntryList(List<Entry> entryList) { - this.entryList = entryList; - } - - public String getObject() { - return object; - } - - public void setObject(String object) { - this.object = object; - } - -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/PlatformUser.java b/src/main/java/com/rekoe/module/facebook/pay/PlatformUser.java deleted file mode 100644 index b2cc7d9..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/PlatformUser.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.rekoe.module.facebook.pay; - -public class PlatformUser { - - private String id; - private String name; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/src/main/java/com/rekoe/module/facebook/pay/RefundableAmount.java b/src/main/java/com/rekoe/module/facebook/pay/RefundableAmount.java deleted file mode 100644 index ae24752..0000000 --- a/src/main/java/com/rekoe/module/facebook/pay/RefundableAmount.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.rekoe.module.facebook.pay; - -public class RefundableAmount { - - private String currency; - private String amount; - - public String getCurrency() { - return currency; - } - - public void setCurrency(String currency) { - this.currency = currency; - } - - public String getAmount() { - return amount; - } - - public void setAmount(String amount) { - this.amount = amount; - } -} diff --git a/src/main/java/com/rekoe/service/ProjectService.java b/src/main/java/com/rekoe/service/ProjectService.java index 7d8ca04..8b87fbf 100644 --- a/src/main/java/com/rekoe/service/ProjectService.java +++ b/src/main/java/com/rekoe/service/ProjectService.java @@ -61,6 +61,8 @@ public class ProjectService extends BaseService<Pj> { return num; } + @Inject + private RepositoryService repositoryService; /** * 保存。<br> * 数据库里已经存在相同的路径或url的项目,不可以保存。<br> @@ -115,6 +117,7 @@ public class ProjectService extends BaseService<Pj> { pjAuth.setRw("rw"); pjAuth.setGr(Constants.GROUP_MANAGER); projectAuthService.saveByGr(pjAuth); + repositoryService.createDir(pj); } else { dao().update(pj); } diff --git a/src/main/java/com/rekoe/service/RepositoryService.java b/src/main/java/com/rekoe/service/RepositoryService.java index 0331d43..58f5056 100644 --- a/src/main/java/com/rekoe/service/RepositoryService.java +++ b/src/main/java/com/rekoe/service/RepositoryService.java @@ -5,6 +5,7 @@ package com.rekoe.service; import java.io.File; import java.util.Collection; +import java.util.List; import org.apache.commons.lang3.StringUtils; import org.nutz.dao.Cnd; @@ -13,6 +14,7 @@ import org.nutz.ioc.loader.annotation.IocBean; import org.nutz.log.Log; import org.nutz.log.Logs; import org.tmatesoft.svn.core.SVNAuthenticationException; +import org.tmatesoft.svn.core.SVNCommitInfo; import org.tmatesoft.svn.core.SVNDirEntry; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.SVNProperties; @@ -23,11 +25,14 @@ import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl; import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; +import org.tmatesoft.svn.core.wc.SVNClientManager; +import org.tmatesoft.svn.core.wc.SVNCommitClient; import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNWCUtil; import com.rekoe.domain.Pj; import com.rekoe.domain.PjUsr; +import com.rekoe.domain.ProjectConfig; import com.rekoe.domain.Usr; import com.rekoe.utils.EncryptUtil; import com.rekoe.utils.UsrProvider; @@ -43,6 +48,7 @@ public class RepositoryService { */ private final Log LOG = Logs.get(); + private SVNClientManager manager; @Inject private ProjectService projectService; @@ -127,6 +133,68 @@ public class RepositoryService { return repository; } + @Inject + private ProjectConfigService projectConfigService; + + public String getProjectSVNUrl(Pj pj) { + ProjectConfig conf = projectConfigService.get(); + String svnurl = conf.getDomainPath() + pj.getPj(); + return parseURL(svnurl); + } + + /** + * 创建初始化的文件夹 + * + * @param pj + * @throws SVNException + */ + public synchronized void createDir(Pj pj) { + Usr usr = UsrProvider.getCurrentUsr(); + String svnUrl = getProjectSVNUrl(pj); + if (StringUtils.isBlank(svnUrl)) { + throw new RuntimeException("URL不可以为空"); + } + String svnUserName = usr.getUsr(); + String svnPassword = usr.getPsw(); + if (!com.rekoe.utils.Constants.HTTP_MUTIL.equals(pj.getType())) { + // pj_usr覆盖用户的密码 + PjUsr pjUsr = projectUserService.get(pj.getPj(), svnUserName); + if (pjUsr != null) { + svnPassword = pjUsr.getPsw(); + } + } + svnPassword = EncryptUtil.decrypt(svnPassword);// 解密 + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(svnUserName, svnPassword); + this.manager.setAuthenticationManager(authManager); + boolean makeParents = true; + String commitMessage = "mkdir by Rekoe"; + ProjectConfig conf = projectConfigService.get(); + List<String> dirs = conf.getDirs(); + SVNURL[] urlAr = new SVNURL[dirs.size()]; + int i = 0; + for (String url : dirs) { + try { + urlAr[i] = SVNURL.parseURIEncoded(url); + } catch (SVNException e) { + LOG.error(e); + } + i++; + } + SVNCommitClient commitClient = SVNClientManager.newInstance().getCommitClient(); + try { + SVNCommitInfo info = commitClient.doMkDir(urlAr, commitMessage, null, makeParents); + if (LOG.isDebugEnabled()) { + long newRevision = info.getNewRevision(); + if (newRevision >= 0) + LOG.debug("commit successful: new revision = " + newRevision); + else + LOG.debug("no commits performed (commit operation returned new revision < 0)"); + } + } catch (SVNException e) { + LOG.error(e); + } + } + /** * 返回项目仓库的根 * @@ -219,6 +287,8 @@ public class RepositoryService { * For using over file:/// */ FSRepositoryFactory.setup(); + + this.manager = SVNClientManager.newInstance(); } }