Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UsersDojoJava
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
LNGCodingDojo
UsersDojoJava
Commits
f8acdc33
Commit
f8acdc33
authored
Mar 29, 2017
by
Boros Andras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
User, right, user_x_right
parent
784aa1c0
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
287 additions
and
13 deletions
+287
-13
DojoRight.java
src/main/java/hu/lanoga/dojo/api/right/DojoRight.java
+29
-0
DojoRightController.java
...in/java/hu/lanoga/dojo/api/right/DojoRightController.java
+67
-0
DojoRightRepository.java
...in/java/hu/lanoga/dojo/api/right/DojoRightRepository.java
+20
-0
DojoRightService.java
src/main/java/hu/lanoga/dojo/api/right/DojoRightService.java
+39
-0
DojoUser.java
src/main/java/hu/lanoga/dojo/api/user/DojoUser.java
+58
-4
DojoUserController.java
...main/java/hu/lanoga/dojo/api/user/DojoUserController.java
+36
-6
DojoUserService.java
src/main/java/hu/lanoga/dojo/api/user/DojoUserService.java
+12
-0
DatasourceConfiguration.java
...n/java/hu/lanoga/dojo/config/DatasourceConfiguration.java
+2
-1
LngComboTextValueEntity.java
...ain/java/hu/lanoga/dojo/util/LngComboTextValueEntity.java
+22
-0
database.properties
src/main/resources/profiles/dev/database.properties
+2
-2
No files found.
src/main/java/hu/lanoga/dojo/api/right/DojoRight.java
0 → 100644
View file @
f8acdc33
package
hu
.
lanoga
.
dojo
.
api
.
right
;
import
lombok.Getter
;
import
lombok.Setter
;
import
javax.persistence.*
;
/**
* Dojo user right
*
* Created by borosandras on 2017. 03. 22..
*/
@Getter
@Setter
@Entity
@Table
(
name
=
"dojo_right"
)
public
class
DojoRight
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Integer
id
;
private
String
name
;
public
DojoRight
(
String
name
)
{
this
.
name
=
name
;
}
public
DojoRight
()
{
}
}
src/main/java/hu/lanoga/dojo/api/right/DojoRightController.java
0 → 100644
View file @
f8acdc33
package
hu
.
lanoga
.
dojo
.
api
.
right
;
import
hu.lanoga.dojo.util.LngComboTextValueEntity
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* Created by borosandras on 2017. 03. 28..
*/
@RestController
@CrossOrigin
(
origins
=
"*"
)
@RequestMapping
(
value
=
"api/right"
)
@Api
(
basePath
=
"/api/right"
,
value
=
"DojoRight"
,
description
=
"Endpoint for right management"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
class
DojoRightController
{
@Autowired
private
DojoRightService
dojoRightService
;
@ApiOperation
(
value
=
"Get right list"
)
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
List
<
DojoRight
>
getRightList
()
{
return
dojoRightService
.
getAllRight
();
}
@ApiOperation
(
value
=
"Get right list for combo"
)
@RequestMapping
(
value
=
"get-rights-for-combo"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
List
<
LngComboTextValueEntity
>
getRightListForCombo
()
{
return
dojoRightService
.
getRightsForCombo
();
}
@ApiOperation
(
value
=
"Get right with specified id"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
DojoRight
getRight
(
@PathVariable
(
"id"
)
Integer
id
)
{
return
dojoRightService
.
getRight
(
id
);
}
@ApiOperation
(
value
=
"Get save new right"
)
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
DojoRight
addRight
(
@RequestBody
DojoRight
user
)
{
return
dojoRightService
.
saveRight
(
user
);
}
@ApiOperation
(
value
=
"Get update right"
)
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
PUT
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
DojoRight
editRight
(
@RequestBody
DojoRight
user
)
{
return
dojoRightService
.
saveRight
(
user
);
}
@ApiOperation
(
value
=
"Delete right with given id"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
DELETE
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
void
deleteRight
(
@PathVariable
(
"id"
)
Integer
id
)
{
dojoRightService
.
removeRight
(
id
);
}
}
src/main/java/hu/lanoga/dojo/api/right/DojoRightRepository.java
0 → 100644
View file @
f8acdc33
package
hu
.
lanoga
.
dojo
.
api
.
right
;
import
hu.lanoga.dojo.util.LngJpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.stereotype.Repository
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* Created by borosandras on 2017. 03. 23..
*/
@Repository
public
interface
DojoRightRepository
extends
LngJpaRepository
<
DojoRight
,
Serializable
>
{
@Query
(
value
=
"select d from DojoRight d"
)
List
<
DojoRight
>
findAllRight
();
}
src/main/java/hu/lanoga/dojo/api/right/DojoRightService.java
0 → 100644
View file @
f8acdc33
package
hu
.
lanoga
.
dojo
.
api
.
right
;
import
hu.lanoga.dojo.util.LngComboTextValueEntity
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* Created by borosandras on 2017. 03. 23..
*/
@Service
public
class
DojoRightService
{
@Autowired
private
DojoRightRepository
dojoRightRepository
;
public
List
<
DojoRight
>
getAllRight
()
{
return
dojoRightRepository
.
findAll
();
}
public
DojoRight
saveRight
(
DojoRight
user
)
{
return
dojoRightRepository
.
saveAndFlush
(
user
);
}
public
void
removeRight
(
Integer
id
)
{
dojoRightRepository
.
delete
(
id
);
}
public
DojoRight
getRight
(
Integer
id
)
{
return
dojoRightRepository
.
findOne
(
id
);
}
public
List
<
LngComboTextValueEntity
>
getRightsForCombo
()
{
return
dojoRightRepository
.
findAll
().
stream
()
.
map
(
right
->
new
LngComboTextValueEntity
(
right
.
getId
(),
right
.
getName
()))
.
collect
(
Collectors
.
toList
());
}
}
src/main/java/hu/lanoga/dojo/api/user/DojoUser.java
View file @
f8acdc33
package
hu
.
lanoga
.
dojo
.
api
.
user
;
import
lombok.Getter
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
hu.lanoga.dojo.api.right.DojoRight
;
import
hu.lanoga.dojo.util.LngComboTextValueEntity
;
import
lombok.Setter
;
import
javax.persistence.*
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* Dojo user entity
*
* Created by borosandras on 2017. 03. 22..
*/
@Getter
@Setter
@Entity
@Table
(
name
=
"dojo_user"
)
...
...
@@ -18,13 +24,61 @@ public class DojoUser {
private
Integer
id
;
private
String
firstName
;
private
String
lastName
;
private
String
userName
;
@JsonFormat
(
shape
=
JsonFormat
.
Shape
.
STRING
,
pattern
=
"yyyy-MM-dd"
)
private
Date
birthDate
;
@ManyToMany
(
fetch
=
FetchType
.
EAGER
)
@JoinTable
(
name
=
"user_x_right"
,
joinColumns
=
{
@JoinColumn
(
name
=
"user_id"
)},
inverseJoinColumns
=
{
@JoinColumn
(
name
=
"right_id"
)})
private
List
<
DojoRight
>
rights
;
public
DojoUser
(
Integer
id
,
String
firstName
,
String
lastName
)
{
this
.
id
=
id
;
public
DojoUser
(
String
firstName
,
String
lastName
,
String
userName
,
Date
birthDate
,
List
<
DojoRight
>
rights
)
{
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
this
.
userName
=
userName
;
this
.
birthDate
=
birthDate
;
this
.
rights
=
rights
;
}
public
DojoUser
()
{
}
public
Integer
getId
()
{
return
id
;
}
public
String
getFirstName
()
{
return
firstName
;
}
public
String
getLastName
()
{
return
lastName
;
}
public
String
getUserName
()
{
return
userName
;
}
public
Date
getBirthDate
()
{
return
birthDate
;
}
/**
* Transform user rights to an acceptable format for the ui
*
* @return List of id-text paierd entity for UI Combo
*/
public
List
<
LngComboTextValueEntity
>
getRights
()
{
return
rights
.
stream
()
.
map
(
right
->
new
LngComboTextValueEntity
(
right
.
getId
(),
right
.
getName
()))
.
collect
(
Collectors
.
toList
());
}
/**
* Return the original right array
*
* @return List of owned rights
*/
public
List
<
DojoRight
>
getRightsEntity
()
{
return
rights
;
}
}
src/main/java/hu/lanoga/dojo/api/user/DojoUserController.java
View file @
f8acdc33
package
hu
.
lanoga
.
dojo
.
api
.
user
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
...
...
@@ -14,16 +13,47 @@ import java.util.List;
* Created by borosandras on 2017. 03. 28..
*/
@RestController
@RequestMapping
(
value
=
"user"
)
@CrossOrigin
(
origins
=
"*"
)
@RequestMapping
(
value
=
"api/user"
)
@Api
(
basePath
=
"/api/user"
,
value
=
"DojoUser"
,
description
=
"Endpoint for user management"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
class
DojoUserController
{
@Autowired
private
DojoUserService
dojoUserService
;
@ApiOperation
(
value
=
"Get user list"
)
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
List
<
DojoUser
>
dummyGetCall
()
{
public
List
<
DojoUser
>
getUserList
()
{
return
dojoUserService
.
getAllUser
();
}
@ApiOperation
(
value
=
"Get user with specified id"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
DojoUser
getUser
(
@PathVariable
(
"id"
)
Integer
id
)
{
return
dojoUserService
.
getUser
(
id
);
}
@ApiOperation
(
value
=
"Get save new user"
)
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
DojoUser
addUser
(
@RequestBody
DojoUser
user
)
{
return
dojoUserService
.
saveUser
(
user
);
}
@ApiOperation
(
value
=
"Get update user"
)
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
PUT
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
DojoUser
editUser
(
@RequestBody
DojoUser
user
)
{
return
dojoUserService
.
saveUser
(
user
);
}
@ApiOperation
(
value
=
"Delete user with given id"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
DELETE
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
void
deleteUser
(
@PathVariable
(
"id"
)
Integer
id
)
{
dojoUserService
.
removeUser
(
id
);
}
}
src/main/java/hu/lanoga/dojo/api/user/DojoUserService.java
View file @
f8acdc33
...
...
@@ -16,4 +16,16 @@ public class DojoUserService {
public
List
<
DojoUser
>
getAllUser
()
{
return
dojoUserRepository
.
findAllUser
();
}
public
DojoUser
saveUser
(
DojoUser
user
)
{
return
dojoUserRepository
.
saveAndFlush
(
user
);
}
public
void
removeUser
(
Integer
id
)
{
dojoUserRepository
.
delete
(
id
);
}
public
DojoUser
getUser
(
Integer
id
)
{
return
dojoUserRepository
.
findOne
(
id
);
}
}
src/main/java/hu/lanoga/dojo/config/DatasourceConfiguration.java
View file @
f8acdc33
...
...
@@ -8,6 +8,7 @@ import org.hibernate.cfg.Environment;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.data.jpa.repository.config.EnableJpaRepositories
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.orm.hibernate4.HibernateExceptionTranslator
;
...
...
@@ -25,7 +26,6 @@ import java.util.Properties;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories
(
basePackageClasses
=
UsersDojoJavaApplication
.
class
,
repositoryFactoryBeanClass
=
LngRepositoryFactoryBean
.
class
,
entityManagerFactoryRef
=
"configureEntityManagerFactory"
)
//@EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
public
class
DatasourceConfiguration
implements
TransactionManagementConfigurer
{
@Value
(
"${datasource.url}"
)
...
...
@@ -55,6 +55,7 @@ public class DatasourceConfiguration implements TransactionManagementConfigurer
}
@Bean
@Primary
public
DataSource
dataSource
()
{
HikariConfig
config
=
new
HikariConfig
();
config
.
setDriverClassName
(
driverClassName
);
...
...
src/main/java/hu/lanoga/dojo/util/LngComboTextValueEntity.java
0 → 100644
View file @
f8acdc33
package
hu
.
lanoga
.
dojo
.
util
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* Created by borosandras on 2017. 03. 29..
*/
@Getter
@Setter
public
class
LngComboTextValueEntity
{
private
Integer
id
;
private
String
text
;
public
LngComboTextValueEntity
(
Integer
id
,
String
text
)
{
this
.
id
=
id
;
this
.
text
=
text
;
}
public
LngComboTextValueEntity
()
{
}
}
src/main/resources/profiles/dev/database.properties
View file @
f8acdc33
...
...
@@ -5,4 +5,4 @@ datasource.driverClassName=org.postgresql.Driver
hibernate.dialect
=
org.hibernate.dialect.PostgreSQLDialect
hibernate.sql.show
=
false
hibernate.hbm2ddl.auto
=
create
\ No newline at end of file
hibernate.hbm2ddl.auto
=
upda
\ No newline at end of file
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