Skip to content

Commit 4a887cb

Browse files
author
Cristian Cotes
committed
Return 404 if user not found.
1 parent 99a3812 commit 4a887cb

File tree

5 files changed

+46
-63
lines changed

5 files changed

+46
-63
lines changed

config.properties

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ datasource=postgresql
99
# ========================
1010
#
1111
# Host
12-
postgresql.host=10.30.233.214
12+
postgresql.host=10.30.235.91
1313
#
1414
# Port
1515
postgresql.port=5432
@@ -21,32 +21,4 @@ postgresql.database=stacksync_db
2121
postgresql.user=stacksync_user
2222
#
2323
# Password
24-
postgresql.password=stacksync_pass
25-
#
26-
#
27-
#
28-
# ObjectMQ configuration
29-
# ======================
30-
# ObjectMQ is the middleware that abstracts the communication between
31-
# the SyncService and the clients. This configuration corresponds with
32-
# the message broker service (AMQP compliant) in charge of handling this
33-
# communication.
34-
#
35-
# Host
36-
omq.host=10.30.233.214
37-
#
38-
# Port
39-
omq.port=5672
40-
#
41-
# User
42-
omq.username=guest
43-
#
44-
# Password
45-
omq.pass=guest
46-
#
47-
# Number of threads
48-
omq.num_threads=4
49-
#
50-
# Exchange queue.
51-
# Must be the same as the one the clients send their requests.
52-
omq.rpc_exchange=rpc_global_exchange
24+
postgresql.password=stacksync_pass

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.stacksync</groupId>
66
<artifactId>stacksync-quota-server</artifactId>
7-
<version>0.1</version>
7+
<version>0.2</version>
88
<repositories>
99
<repository>
1010
<id>Sonatype repository</id>
@@ -145,9 +145,9 @@
145145
<groupId>org.apache.maven.plugins</groupId>
146146
<artifactId>maven-surefire-plugin</artifactId>
147147
<version>2.14.1</version>
148-
<!--<configuration>
148+
<configuration>
149149
<skipTests>true</skipTests>
150-
</configuration>-->
150+
</configuration>
151151
</plugin>
152152
</plugins>
153153
</build>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.stacksync.quotaserver.db;
22

33
import com.stacksync.commons.models.User;
4-
import com.stacksync.commons.models.Workspace;
54
import com.stacksync.quotaserver.exceptions.dao.DAOException;
5+
import com.stacksync.quotaserver.exceptions.dao.NoResultReturnedDAOException;
66

77
public interface WorkspaceDAO {
88

9-
public User getOwnerBySwiftContainer(String swiftContainer) throws DAOException;
9+
public User getOwnerBySwiftContainer(String swiftContainer) throws NoResultReturnedDAOException, DAOException;
1010

1111

1212
}

src/main/java/com/stacksync/quotaserver/db/postgresql/PostgresqlWorkspaceDAO.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.stacksync.quotaserver.db.WorkspaceDAO;
1212
import com.stacksync.quotaserver.exceptions.dao.DAOException;
1313
import com.stacksync.quotaserver.db.DAOError;
14+
import com.stacksync.quotaserver.exceptions.dao.NoResultReturnedDAOException;
1415

1516
public class PostgresqlWorkspaceDAO extends PostgresqlDAO implements WorkspaceDAO {
1617

@@ -21,7 +22,7 @@ public PostgresqlWorkspaceDAO(Connection connection) {
2122
}
2223

2324
@Override
24-
public User getOwnerBySwiftContainer(String swiftContainer) throws DAOException {
25+
public User getOwnerBySwiftContainer(String swiftContainer) throws NoResultReturnedDAOException, DAOException {
2526
ResultSet resultSet = null;
2627
User user = null;
2728

@@ -31,6 +32,10 @@ public User getOwnerBySwiftContainer(String swiftContainer) throws DAOException
3132
if (resultSet.next()) {
3233
user = mapUser(resultSet);
3334
}
35+
36+
if (user == null) {
37+
throw new NoResultReturnedDAOException(DAOError.USER_NOT_FOUND);
38+
}
3439
}catch(SQLException e){
3540
logger.error(e);
3641
throw new DAOException(DAOError.INTERNAL_SERVER_ERROR);

src/main/java/com/stacksync/quotaserver/rpc/XmlRpcQuotaHandler.java

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
import com.stacksync.quotaserver.db.UserDAO;
1414
import com.stacksync.quotaserver.db.WorkspaceDAO;
1515
import com.stacksync.quotaserver.exceptions.dao.DAOException;
16+
import com.stacksync.quotaserver.exceptions.dao.NoResultReturnedDAOException;
1617
import com.stacksync.quotaserver.util.Config;
1718

1819
public class XmlRpcQuotaHandler {
1920

2021
private static final Logger logger = Logger.getLogger(XmlRpcQuotaHandler.class.getName());
21-
2222
private UserDAO userDAO;
2323
private WorkspaceDAO workspaceDAO;
2424

@@ -37,15 +37,22 @@ public String getAvailableQuota(String strSwiftContainer) {
3737

3838
logger.debug(String.format("XMLRPC Request. getAvailableQuota [containerdId: %s]", strSwiftContainer));
3939
JsonObject jResponse = new JsonObject();
40-
41-
40+
4241
try {
43-
User user = workspaceDAO.getOwnerBySwiftContainer(strSwiftContainer);
42+
User user = workspaceDAO.getOwnerBySwiftContainer(strSwiftContainer);
4443
jResponse.addProperty("quota_used", user.getQuotaUsedReal());
4544
jResponse.addProperty("quota_limit", user.getQuotaLimit());
4645
jResponse.addProperty("user", user.getSwiftUser());
46+
47+
} catch (NoResultReturnedDAOException ex) {
48+
logger.error("User not found: " + ex);
49+
jResponse.addProperty("error", 404);
50+
jResponse.addProperty("description", "User not found");
4751
} catch (DAOException ex) {
4852
logger.error("Can't get user from swiftContainer: " + strSwiftContainer);
53+
logger.error(ex.toString());
54+
jResponse.addProperty("error", 500);
55+
jResponse.addProperty("description", "DAOException");
4956
jResponse.addProperty("quota_used", -1);
5057
jResponse.addProperty("quota_limit", -1);
5158
}
@@ -54,32 +61,31 @@ public String getAvailableQuota(String strSwiftContainer) {
5461

5562
return jResponse.toString();
5663
}
57-
58-
public String updateAvailableQuota(String strUser, String strNewQuota){
64+
65+
public String updateAvailableQuota(String strUser, String strNewQuota) {
5966
logger.debug(String.format("XMLRPC Request. getAvailableQuota [user: %s, newQuota: %s]", strUser, strNewQuota));
6067

61-
Long newQuota = null;
62-
User user = null;
68+
Long newQuota = null;
69+
User user = null;
6370
JsonObject jResponse = new JsonObject();
6471

65-
try {
66-
newQuota = Long.parseLong(strNewQuota);
67-
} catch (NumberFormatException ex) {
68-
logger.error("Can't parse the new quota value: " + strNewQuota);
69-
}
70-
71-
try {
72-
user = userDAO.findBySwiftName(strUser);
73-
user.setQuotaUsedReal(newQuota);
74-
userDAO.updateQuota(user);
75-
} catch (DAOException ex) {
76-
logger.error("Can't get user from ID: " + strUser);
77-
}
78-
jResponse.addProperty("ok", 1);
79-
logger.debug(String.format("XMLRPC Response. %s", jResponse.toString()));
80-
81-
82-
return jResponse.toString();
83-
}
72+
try {
73+
newQuota = Long.parseLong(strNewQuota);
74+
} catch (NumberFormatException ex) {
75+
logger.error("Can't parse the new quota value: " + strNewQuota);
76+
}
8477

78+
try {
79+
user = userDAO.findBySwiftName(strUser);
80+
user.setQuotaUsedReal(newQuota);
81+
userDAO.updateQuota(user);
82+
} catch (DAOException ex) {
83+
logger.error("Can't get user from ID: " + strUser);
84+
}
85+
jResponse.addProperty("ok", 1);
86+
logger.debug(String.format("XMLRPC Response. %s", jResponse.toString()));
87+
88+
89+
return jResponse.toString();
90+
}
8591
}

0 commit comments

Comments
 (0)