Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
ff83120d
Commit
ff83120d
authored
Mar 02, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added specific excptions
parent
5e0247c7
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
171 additions
and
25 deletions
+171
-25
BadRequestException.java
...va/nl/uva/sne/drip/api/exception/BadRequestException.java
+1
-1
PasswordNullException.java
.../nl/uva/sne/drip/api/exception/PasswordNullException.java
+36
-0
UserExistsException.java
...va/nl/uva/sne/drip/api/exception/UserExistsException.java
+36
-0
UserNotFoundException.java
.../nl/uva/sne/drip/api/exception/UserNotFoundException.java
+36
-0
UserNullException.java
...java/nl/uva/sne/drip/api/exception/UserNullException.java
+36
-0
UserController.java
...rc/main/java/nl/uva/sne/drip/api/rest/UserController.java
+10
-6
PlannerService.java
...main/java/nl/uva/sne/drip/api/service/PlannerService.java
+12
-13
Converter.java
...rc/main/java/nl/uva/sne/drip/commons/utils/Converter.java
+4
-5
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/exception/BadRequestException.java
View file @
ff83120d
...
...
@@ -22,7 +22,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
*
* @author S. Koulouzis
*/
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
)
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
,
reason
=
"MMMMMMMMMMMMMMMMMM"
)
public
class
BadRequestException
extends
RuntimeException
{
public
BadRequestException
(
String
massage
)
{
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/exception/PasswordNullException.java
0 → 100644
View file @
ff83120d
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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
nl
.
uva
.
sne
.
drip
.
api
.
exception
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
,
reason
=
"User already exists"
)
public
class
PasswordNullException
extends
RuntimeException
{
public
PasswordNullException
()
{
super
();
}
public
PasswordNullException
(
String
string
)
{
super
(
string
);
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/exception/UserExistsException.java
0 → 100644
View file @
ff83120d
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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
nl
.
uva
.
sne
.
drip
.
api
.
exception
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
,
reason
=
"User already exists"
)
public
class
UserExistsException
extends
RuntimeException
{
public
UserExistsException
()
{
super
();
}
public
UserExistsException
(
String
string
)
{
super
(
string
);
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/exception/UserNotFoundException.java
0 → 100644
View file @
ff83120d
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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
nl
.
uva
.
sne
.
drip
.
api
.
exception
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus
(
value
=
HttpStatus
.
NOT_FOUND
,
reason
=
"User not found"
)
public
class
UserNotFoundException
extends
RuntimeException
{
public
UserNotFoundException
(
String
string
)
{
super
(
string
);
}
public
UserNotFoundException
()
{
super
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/exception/UserNullException.java
0 → 100644
View file @
ff83120d
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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
nl
.
uva
.
sne
.
drip
.
api
.
exception
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
,
reason
=
"User name can't be null"
)
public
class
UserNullException
extends
RuntimeException
{
public
UserNullException
(
String
massage
)
{
super
(
massage
);
}
public
UserNullException
()
{
super
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/rest/UserController.java
View file @
ff83120d
...
...
@@ -22,6 +22,10 @@ import java.util.logging.Logger;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.exception.PasswordNullException
;
import
nl.uva.sne.drip.api.exception.UserExistsException
;
import
nl.uva.sne.drip.api.exception.UserNotFoundException
;
import
nl.uva.sne.drip.api.exception.UserNullException
;
import
nl.uva.sne.drip.commons.types.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -62,14 +66,14 @@ public class UserController {
public
@ResponseBody
String
register
(
@RequestBody
User
user
)
{
if
(
user
.
getUsername
()
==
null
)
{
throw
new
BadRequestException
(
"Username can't be null"
);
throw
new
UserNullException
(
);
}
if
(
user
.
getPassword
()
==
null
)
{
throw
new
BadRequestException
(
"Password can't be null"
);
throw
new
PasswordNullException
(
);
}
UserDetails
registeredUser
=
service
.
loadUserByUsername
(
user
.
getUsername
());
if
(
registeredUser
!=
null
)
{
throw
new
BadRequest
Exception
(
"Username "
+
user
.
getUsername
()
+
" is used"
);
throw
new
UserExists
Exception
(
"Username "
+
user
.
getUsername
()
+
" is used"
);
}
user
.
setPassword
(
new
BCryptPasswordEncoder
().
encode
(
user
.
getPassword
()));
service
.
getDao
().
save
(
user
);
...
...
@@ -82,7 +86,7 @@ public class UserController {
String
modify
(
@RequestBody
User
user
)
{
UserDetails
registeredUser
=
service
.
loadUserByUsername
(
user
.
getUsername
());
if
(
registeredUser
==
null
)
{
throw
new
NotFoundException
(
"User "
+
user
.
getUsername
()
+
" not found"
);
throw
new
User
NotFoundException
(
"User "
+
user
.
getUsername
()
+
" not found"
);
}
return
this
.
register
(
user
);
}
...
...
@@ -94,7 +98,7 @@ public class UserController {
try
{
User
user
=
service
.
getDao
().
findOne
(
id
);
if
(
user
==
null
)
{
throw
new
NotFoundException
(
);
throw
new
UserNotFoundException
(
"User "
+
id
+
" not found"
);
}
return
user
;
}
catch
(
Exception
ex
)
{
...
...
@@ -110,7 +114,7 @@ public class UserController {
try
{
User
user
=
service
.
getDao
().
findOne
(
id
);
if
(
user
==
null
)
{
throw
new
NotFoundException
(
);
throw
new
UserNotFoundException
(
"User "
+
id
+
" not found"
);
}
service
.
getDao
().
delete
(
user
);
return
"Deleted used :"
+
id
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java
View file @
ff83120d
...
...
@@ -31,7 +31,6 @@ import nl.uva.sne.drip.api.rpc.PlannerCaller;
import
nl.uva.sne.drip.commons.types.Message
;
import
nl.uva.sne.drip.commons.types.MessageParameter
;
import
nl.uva.sne.drip.commons.types.Plan
;
import
nl.uva.sne.drip.commons.types.SimplePlanContainer
;
import
nl.uva.sne.drip.commons.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
org.json.JSONException
;
...
...
@@ -64,23 +63,23 @@ public class PlannerService {
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
String
jsonString
=
mapper
.
writeValueAsString
(
plannerReturnedMessage
);
SimplePlanContainer
simplePlan
=
Converter
.
plannerOutput2SimplePlanContainer
(
jsonString
);
//
SimplePlanContainer simplePlan = Converter.plannerOutput2SimplePlanContainer(jsonString);
Plan
topLevel
=
new
Plan
();
topLevel
.
setLevel
(
0
);
topLevel
.
setToscaID
(
toscaId
);
topLevel
.
setName
(
"planner_output_all.yml"
);
topLevel
.
setKvMap
(
Converter
.
ymlString2Map
(
simplePlan
.
getTopLevel
()));
Map
<
String
,
String
>
map
=
simplePlan
.
getLowerLevels
();
//
topLevel.setKvMap(Converter.ymlString2Map(simplePlan.getTopLevel()));
//
Map<String, String> map = simplePlan.getLowerLevels();
Set
<
String
>
loweLevelPlansIDs
=
new
HashSet
<>();
for
(
String
lowLevelNames
:
map
.
keySet
())
{
Plan
lowLevelPlan
=
new
Plan
();
lowLevelPlan
.
setLevel
(
1
);
lowLevelPlan
.
setToscaID
(
toscaId
);
lowLevelPlan
.
setName
(
lowLevelNames
);
lowLevelPlan
.
setKvMap
(
Converter
.
ymlString2Map
(
map
.
get
(
lowLevelNames
)));
planDao
.
save
(
lowLevelPlan
);
loweLevelPlansIDs
.
add
(
lowLevelPlan
.
getId
());
}
//
for (String lowLevelNames : map.keySet()) {
//
Plan lowLevelPlan = new Plan();
//
lowLevelPlan.setLevel(1);
//
lowLevelPlan.setToscaID(toscaId);
//
lowLevelPlan.setName(lowLevelNames);
//
lowLevelPlan.setKvMap(Converter.ymlString2Map(map.get(lowLevelNames)));
//
planDao.save(lowLevelPlan);
//
loweLevelPlansIDs.add(lowLevelPlan.getId());
//
}
topLevel
.
setLoweLevelPlansIDs
(
loweLevelPlansIDs
);
planDao
.
save
(
topLevel
);
...
...
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
ff83120d
...
...
@@ -71,11 +71,10 @@ public class Converter {
return
jsonObject2Map
(
jsonObject
);
}
public
static
SimplePlanContainer
plannerOutput2SimplePlanContainer
(
String
jsonString
)
throws
JSONException
{
return
null
;
}
// public static SimplePlanContainer plannerOutput2SimplePlanContainer(String jsonString) throws JSONException {
//
// return null;
// }
public
static
Map
<
String
,
Object
>
jsonObject2Map
(
JSONObject
object
)
throws
JSONException
{
Map
<
String
,
Object
>
map
=
new
HashMap
();
...
...
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