Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
157a51f6
Commit
157a51f6
authored
Mar 14, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Privilege service,repo,controller and test in Portal
parent
fa1c4fe3
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
231 additions
and
27 deletions
+231
-27
PrivilegeController.java
...m/ctrip/apollo/portal/controller/PrivilegeController.java
+10
-0
App.java
...tal/src/main/java/com/ctrip/apollo/portal/entity/App.java
+5
-5
Privilege.java
...c/main/java/com/ctrip/apollo/portal/entity/Privilege.java
+62
-0
PrivilegeRepository.java
...m/ctrip/apollo/portal/repository/PrivilegeRepository.java
+14
-0
PrivilegeService.java
...ava/com/ctrip/apollo/portal/service/PrivilegeService.java
+41
-0
AllTests.java
...ortal/src/test/java/com/ctrip/apollo/portal/AllTests.java
+17
-0
AppControllerTest.java
...com/ctrip/apollo/portal/controller/AppControllerTest.java
+7
-7
AppRepositoryTest.java
...com/ctrip/apollo/portal/repository/AppRepositoryTest.java
+1
-1
PrivilegeServiceTest.java
...com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
+64
-0
pom.xml
framework-parent/pom.xml
+9
-13
pom.xml
pom.xml
+1
-1
No files found.
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/PrivilegeController.java
0 → 100644
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment