Adapt quota server to works using container name and return its owner · stacksync/stacksync-quota-server@ad952b4 · GitHub
Skip to content

Commit ad952b4

Browse files
committed
Adapt quota server to works using container name and return its owner
1 parent 141b954 commit ad952b4

3 files changed

Lines changed: 78 additions & 5 deletions

File tree

Lines changed: 12 additions & 0 deletions
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.stacksync.quotaserver.db.postgresql;
2+
3+
import java.sql.Connection;
4+
import java.sql.ResultSet;
5+
import java.sql.SQLException;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.UUID;
9+
10+
import org.apache.log4j.Logger;
11+
12+
import com.stacksync.commons.models.User;
13+
import com.stacksync.commons.models.Workspace;
14+
import com.stacksync.quotaserver.db.WorkspaceDAO;
15+
import com.stacksync.quotaserver.exceptions.dao.DAOException;
16+
import com.stacksync.quotaserver.db.DAOError;
17+
18+
public class PostgresqlWorkspaceDAO extends PostgresqlDAO implements WorkspaceDAO {
19+
20+
private static final Logger logger = Logger.getLogger(PostgresqlWorkspaceDAO.class.getName());
21+
22+
public PostgresqlWorkspaceDAO(Connection connection) {
23+
super(connection);
24+
}
25+
26+
private User mapUser(ResultSet resultSet) throws SQLException {
27+
User user = new User();
28+
user.setId(UUID.fromString(resultSet.getString("id")));
29+
user.setEmail(resultSet.getString("email"));
30+
user.setName(resultSet.getString("name"));
31+
user.setSwiftUser(resultSet.getString("swift_user"));
32+
user.setSwiftAccount(resultSet.getString("swift_account"));
33+
user.setQuotaLimit(resultSet.getLong("quota_limit"));
34+
user.setQuotaUsedLogical(resultSet.getLong("quota_used_logical"));
35+
user.setQuotaUsedReal(resultSet.getLong("quota_used_real"));
36+
return user;
37+
}
38+
39+
@Override
40+
public User getOwnerBySwiftContainer(String swiftContainer) throws DAOException {
41+
ResultSet resultSet = null;
42+
User user = null;
43+
44+
String query = "SELECT * FROM user1 u where id = (SELECT owner_id FROM workspace where swift_container=?)";
45+
try{
46+
resultSet = executeQuery(query, new Object[] { swiftContainer });
47+
if (resultSet.next()) {
48+
user = mapUser(resultSet);
49+
}
50+
}catch(SQLException e){
51+
logger.error(e);
52+
throw new DAOException(DAOError.INTERNAL_SERVER_ERROR);
53+
54+
}
55+
return user;
56+
}
57+
}

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

Lines changed: 9 additions & 5 deletions

0 commit comments

Comments
 (0)