Revision 01a30cd0 src/gr/ebs/gss/server/ejb/ExternalAPIBean.java

b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java
22 22
import gr.ebs.gss.client.exceptions.DuplicateNameException;
23 23
import gr.ebs.gss.client.exceptions.GSSIOException;
24 24
import gr.ebs.gss.client.exceptions.InsufficientPermissionsException;
25
import gr.ebs.gss.client.exceptions.InvitationUsedException;
25 26
import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
26 27
import gr.ebs.gss.client.exceptions.QuotaExceededException;
27 28
import gr.ebs.gss.server.domain.AuditInfo;
......
35 36
import gr.ebs.gss.server.domain.Nonce;
36 37
import gr.ebs.gss.server.domain.Permission;
37 38
import gr.ebs.gss.server.domain.User;
39
import gr.ebs.gss.server.domain.UserClass;
38 40
import gr.ebs.gss.server.domain.dto.FileBodyDTO;
39 41
import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
40 42
import gr.ebs.gss.server.domain.dto.FolderDTO;
......
799 801
		}
800 802
	}
801 803

  
802
	/* (non-Javadoc)
803
	 * @see gr.ebs.gss.server.ejb.ExternalAPI#getFile(java.lang.Long, java.lang.Long)
804
	 */
804
	@Override
805 805
	public FileHeaderDTO getFile(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException {
806 806
		if (userId == null)
807 807
			throw new ObjectNotFoundException("No user specified");
......
1429 1429
		user.setAuditInfo(auditInfo);
1430 1430
		user.generateAuthToken();
1431 1431
		user.generateWebDAVPassword();
1432
		// Set the default user class to the one with the lowest quota.
1433
		user.setUserClass(getUserClasses().get(0));
1432 1434
		dao.create(user);
1433 1435
		// Make sure we get an ID in the user object.
1434 1436
		dao.flush();
......
1438 1440
	}
1439 1441

  
1440 1442
	@Override
1443
	public List<UserClass> getUserClasses() {
1444
		List<UserClass> classes = dao.getUserClasses();
1445
		// Create a default user class for first-time use. Afterwards, the
1446
		// admin should modify or add to the userclass table.
1447
		if (classes.size() == 0) {
1448
			UserClass defaultClass = new UserClass();
1449
			defaultClass.setName("default");
1450
			Long defaultQuota = getConfiguration().getLong("quota", new Long(52428800L));
1451
			defaultClass.setQuota(defaultQuota);
1452
			dao.create(defaultClass);
1453
			classes.add(defaultClass);
1454
		}
1455
		return classes;
1456
	}
1457

  
1458
	@Override
1441 1459
	public User findUserByEmail(String email) {
1442 1460
		return dao.findUserByEmail(email);
1443 1461
	}
......
2134 2152
	}
2135 2153

  
2136 2154
	/**
2137
	 * Gets the quota left for specified userId
2138
	 * @param userId
2139
	 * @return
2155
	 * Gets the quota left for specified user ID.
2140 2156
	 */
2141
	private Long getQuotaLeft(Long userId){
2157
	private Long getQuotaLeft(Long userId) throws ObjectNotFoundException{
2142 2158
		Long fileSize = dao.getFileSize(userId);
2143 2159
		Long quota = getQuota(userId);
2144 2160
		return quota - fileSize;
2145 2161
	}
2146 2162

  
2147 2163
	/**
2148
	 * Gets the quota for specified userId
2149
	 * @param userId
2150
	 * @return
2164
	 * Gets the quota for specified user ID.
2151 2165
	 */
2152
	private Long getQuota(@SuppressWarnings("unused") Long userId){
2153
		Long quota = getConfiguration().getLong("quota", new Long(52428800L));
2154
		return quota;
2166
	private Long getQuota(Long userId) throws ObjectNotFoundException{
2167
		return getUser(userId).getUserClass().getQuota();
2155 2168
	}
2156 2169

  
2157 2170
	public void rebuildSolrIndex() {
......
2435 2448
	 * @param owner the owner of the file
2436 2449
	 * @throws FileNotFoundException
2437 2450
	 * @throws QuotaExceededException
2451
	 * @throws ObjectNotFoundException if the owner was not found
2438 2452
	 */
2439 2453
	private void createFileBody(String name, String mimeType, long fileSize, String filePath,
2440 2454
				FileHeader header, AuditInfo auditInfo)
2441
			throws FileNotFoundException, QuotaExceededException {
2455
			throws FileNotFoundException, QuotaExceededException, ObjectNotFoundException {
2442 2456

  
2443 2457
		long currentTotalSize = 0;
2444 2458
		if (!header.isVersioned() && header.getCurrentBody() != null && header.getBodies() != null)
......
2680 2694

  
2681 2695
	}
2682 2696

  
2697
	@Override
2698
	public void upgradeUserClass(String username, String code) throws ObjectNotFoundException, InvitationUsedException {
2699
		User user = findUser(username);
2700
		if (user == null)
2701
			throw new ObjectNotFoundException("The user was not found");
2702
		Invitation invite = findInvite(code);
2703
		if (invite.getUser() != null)
2704
			throw new InvitationUsedException("This code has already been used");
2705
		invite.setUser(user);
2706
		user.setUserClass(getCouponUserClass());
2707
	}
2708

  
2709
	@Override
2710
	public UserClass getCouponUserClass() {
2711
		return dao.findCouponUserClass();
2712
	}
2713

  
2683 2714
}

Also available in: Unified diff