Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
apollo
提交
157a51f6
apollo
项目概览
zhangjian1949
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
157a51f6
编写于
3月 14, 2016
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Privilege service,repo,controller and test in Portal
上级
fa1c4fe3
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
230 addition
and
27 deletion
+230
-27
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/PrivilegeController.java
...m/ctrip/apollo/portal/controller/PrivilegeController.java
+10
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/App.java
...tal/src/main/java/com/ctrip/apollo/portal/entity/App.java
+5
-5
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/Privilege.java
...c/main/java/com/ctrip/apollo/portal/entity/Privilege.java
+62
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/PrivilegeRepository.java
...m/ctrip/apollo/portal/repository/PrivilegeRepository.java
+14
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/PrivilegeService.java
...ava/com/ctrip/apollo/portal/service/PrivilegeService.java
+41
-0
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
...ortal/src/test/java/com/ctrip/apollo/portal/AllTests.java
+17
-0
apollo-portal/src/test/java/com/ctrip/apollo/portal/controller/AppControllerTest.java
...com/ctrip/apollo/portal/controller/AppControllerTest.java
+7
-7
apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java
...com/ctrip/apollo/portal/repository/AppRepositoryTest.java
+1
-1
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
...com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
+64
-0
framework-parent/pom.xml
framework-parent/pom.xml
+8
-13
pom.xml
pom.xml
+1
-1
未找到文件。
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/PrivilegeController.java
0 → 100644
浏览文件 @
157a51f6
package
com.ctrip.apollo.portal.controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/privileges"
)
public
class
PrivilegeController
{
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/App.java
浏览文件 @
157a51f6
...
...
@@ -16,7 +16,7 @@ public class App implements Serializable {
private
static
final
long
serialVersionUID
=
7348554309210401557L
;
@Id
private
String
i
d
;
private
String
appI
d
;
@Column
(
nullable
=
false
)
private
String
name
;
...
...
@@ -36,12 +36,12 @@ public class App implements Serializable {
@Column
private
Date
lastUpdatedTimestamp
;
public
String
getId
()
{
return
i
d
;
public
String
get
App
Id
()
{
return
appI
d
;
}
public
void
set
Id
(
String
i
d
)
{
this
.
id
=
i
d
;
public
void
set
AppId
(
String
appI
d
)
{
this
.
appId
=
appI
d
;
}
public
String
getName
()
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/Privilege.java
0 → 100644
浏览文件 @
157a51f6
package
com.ctrip.apollo.portal.entity
;
import
java.io.Serializable
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
@Entity
public
class
Privilege
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
430087307622435118L
;
@Id
@GeneratedValue
private
long
id
;
@Column
private
String
name
;
@Column
private
String
privilType
;
@Column
private
String
appId
;
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPrivilType
()
{
return
privilType
;
}
public
void
setPrivilType
(
String
privilType
)
{
this
.
privilType
=
privilType
;
}
public
String
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/PrivilegeRepository.java
0 → 100644
浏览文件 @
157a51f6
package
com.ctrip.apollo.portal.repository
;
import
java.util.List
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
com.ctrip.apollo.portal.entity.Privilege
;
public
interface
PrivilegeRepository
extends
PagingAndSortingRepository
<
Privilege
,
Long
>
{
List
<
Privilege
>
findByAppId
(
String
appId
);
Privilege
findByAppIdAndPrivilType
(
String
appId
,
String
privilType
);
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/PrivilegeService.java
0 → 100644
浏览文件 @
157a51f6
package
com.ctrip.apollo.portal.service
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.portal.entity.Privilege
;
import
com.ctrip.apollo.portal.repository.PrivilegeRepository
;
@Service
public
class
PrivilegeService
{
enum
PrivilType
{
EDIT
,
REVIEW
,
RELEASE
}
@Autowired
private
PrivilegeRepository
privilRepo
;
public
boolean
hasPrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndPrivilType
(
appId
,
privilType
.
name
());
if
(
privil
!=
null
&&
privil
.
getName
().
equals
(
name
))
return
true
;
return
false
;
}
public
List
<
Privilege
>
listPrivileges
(
String
appId
)
{
return
privilRepo
.
findByAppId
(
appId
);
}
public
Privilege
setPrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndPrivilType
(
appId
,
privilType
.
name
());
if
(
privil
==
null
)
{
privil
=
new
Privilege
();
privil
.
setAppId
(
appId
);
privil
.
setPrivilType
(
privilType
.
name
());
}
privil
.
setName
(
name
);
return
privilRepo
.
save
(
privil
);
}
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
0 → 100644
浏览文件 @
157a51f6
package
com.ctrip.apollo.portal
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
com.ctrip.apollo.portal.controller.AppControllerTest
;
import
com.ctrip.apollo.portal.repository.AppRepositoryTest
;
import
com.ctrip.apollo.portal.service.PrivilegeServiceTest
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
AppControllerTest
.
class
,
AppRepositoryTest
.
class
,
PrivilegeServiceTest
.
class
,
})
public
class
AllTests
{
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/controller/AppControllerTest.java
浏览文件 @
157a51f6
...
...
@@ -28,26 +28,26 @@ public class AppControllerTest extends AbstractPortalTest {
@Test
public
void
testCreate
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
newApp
.
setId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
set
App
Id
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
URI
uri
=
new
URI
(
"http://localhost:8080/apps"
);
App
createdApp
=
restTemplate
.
postForObject
(
uri
,
newApp
,
App
.
class
);
Assert
.
assertEquals
(
newApp
.
get
Id
(),
createdApp
.
get
Id
());
Assert
.
assertEquals
(
newApp
.
get
AppId
(),
createdApp
.
getApp
Id
());
Assert
.
assertNull
(
newApp
.
getCreateTimestamp
());
Assert
.
assertNotNull
(
createdApp
.
getCreateTimestamp
());
App
foundApp
=
appRepository
.
findOne
(
newApp
.
getId
());
App
foundApp
=
appRepository
.
findOne
(
newApp
.
get
App
Id
());
Assert
.
assertEquals
(
newApp
.
get
Id
(),
foundApp
.
get
Id
());
Assert
.
assertEquals
(
newApp
.
get
AppId
(),
foundApp
.
getApp
Id
());
}
@Test
public
void
testList
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
newApp
.
setId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
set
App
Id
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appRepository
.
save
(
newApp
);
...
...
@@ -56,13 +56,13 @@ public class AppControllerTest extends AbstractPortalTest {
App
[]
apps
=
restTemplate
.
getForObject
(
uri
,
App
[].
class
);
Assert
.
assertEquals
(
1
,
apps
.
length
);
Assert
.
assertEquals
(
newApp
.
get
Id
(),
apps
[
0
].
get
Id
());
Assert
.
assertEquals
(
newApp
.
get
AppId
(),
apps
[
0
].
getApp
Id
());
}
@Test
public
void
testListOutOfRange
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
newApp
.
setId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
set
App
Id
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appRepository
.
save
(
newApp
);
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java
浏览文件 @
157a51f6
...
...
@@ -18,7 +18,7 @@ public class AppRepositoryTest extends AbstractPortalTest{
Assert
.
assertEquals
(
0
,
repository
.
count
());
App
ramdomApp
=
new
App
();
ramdomApp
.
setId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
ramdomApp
.
set
App
Id
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
ramdomApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
ramdomApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
repository
.
save
(
ramdomApp
);
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
0 → 100644
浏览文件 @
157a51f6
package
com.ctrip.apollo.portal.service
;
import
java.util.List
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.ctrip.apollo.portal.AbstractPortalTest
;
import
com.ctrip.apollo.portal.entity.App
;
import
com.ctrip.apollo.portal.entity.Privilege
;
public
class
PrivilegeServiceTest
extends
AbstractPortalTest
{
@Autowired
AppService
appService
;
@Autowired
PrivilegeService
privilService
;
@Test
public
void
testAddPrivilege
()
{
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appService
.
save
(
newApp
);
privilService
.
setPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
);
List
<
Privilege
>
privileges
=
privilService
.
listPrivileges
(
newApp
.
getAppId
());
Assert
.
assertEquals
(
1
,
privileges
.
size
());
Assert
.
assertEquals
(
PrivilegeService
.
PrivilType
.
EDIT
.
name
(),
privileges
.
get
(
0
).
getPrivilType
());
Assert
.
assertEquals
(
newApp
.
getOwner
(),
privileges
.
get
(
0
).
getName
());
}
@Test
public
void
testCheckPrivilege
()
{
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appService
.
save
(
newApp
);
privilService
.
setPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
));
Assert
.
assertFalse
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
REVIEW
));
Assert
.
assertFalse
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
RELEASE
));
privilService
.
setPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
EDIT
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
EDIT
));
Assert
.
assertFalse
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
));
privilService
.
setPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
));
}
}
framework-parent/pom.xml
浏览文件 @
157a51f6
...
...
@@ -4,7 +4,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.ctrip.framework
</groupId>
<artifactId>
framework-parent
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<version>
1.0
</version>
<packaging>
pom
</packaging>
<name>
Ctrip Framework Parent
</name>
<description>
Ctrip Framework Parent
</description>
...
...
@@ -15,7 +15,6 @@
<properties>
<java.version>
1.7
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
</properties>
<build>
<pluginManagement>
...
...
@@ -26,12 +25,8 @@
<version>
2.19.1
</version>
<configuration>
<includes>
<include>
**/*Tests.java
</include>
<include>
**/*Test.java
</include>
<include>
**/AllTests.java
</include>
</includes>
<excludes>
<exclude>
**/Abstract*.java
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
...
...
@@ -104,7 +99,7 @@
<exclude>
javax.servlet:servlet-api
</exclude>
<exclude>
org.mortbay.jetty:servlet-api-2.5
</exclude>
</excludes>
<message>
**
There are some banned dependencies.
</message>
<message>
**
prefer javax.servlet:javax.servlet-api
</message>
</bannedDependencies>
</rules>
</configuration>
...
...
@@ -156,12 +151,12 @@
</build>
<distributionManagement>
<repository>
<id>
ctrip_fx_release
</id>
<url>
${
ctrip.fx.release
.repo}
</url>
<id>
releases
</id>
<url>
${
releases
.repo}
</url>
</repository>
<snapshotRepository>
<id>
ctrip_fx_snapshot
</id>
<url>
${
ctrip.fx.snapshot
.repo}
</url>
<id>
snapshots
</id>
<url>
${
snapshots
.repo}
</url>
</snapshotRepository>
</distributionManagement>
</project>
</project>
\ No newline at end of file
pom.xml
浏览文件 @
157a51f6
...
...
@@ -12,7 +12,7 @@
<parent>
<groupId>
com.ctrip.framework
</groupId>
<artifactId>
framework-parent
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<version>
1.0
</version>
<relativePath>
framework-parent
</relativePath>
</parent>
<organization>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录