Revision 77dcb3f1

b/src/gr/ebs/gss/server/ejb/ExternalAPI.java
248 248
	 * @param userId the ID of the current user
249 249
	 * @param folderId the ID of the folder to retrieve
250 250
	 * @param folderName
251
	 * @return the updated folder
251 252
	 * @throws InsufficientPermissionsException if the user does not have the
252 253
	 *             appropriate privileges
253 254
	 * @throws ObjectNotFoundException if the user or folder was not found, with
......
255 256
	 * @throws DuplicateNameException if the specified name already exists in
256 257
	 *             the parent folder, as either a folder or file
257 258
	 */
258
	public void modifyFolder(Long userId, Long folderId, String folderName)
259
	public FolderDTO modifyFolder(Long userId, Long folderId, String folderName)
259 260
			throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException;
260 261

  
261 262
	/**
b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java
406 406
	}
407 407

  
408 408
	@Override
409
	public void modifyFolder(Long userId, Long folderId, String folderName)
409
	public FolderDTO modifyFolder(Long userId, Long folderId, String folderName)
410 410
			throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException {
411 411

  
412 412
		// Validate.
......
430 430
		// Do the actual modification.
431 431
		folder.setName(folderName);
432 432
		dao.update(folder);
433
		return folder.getDTO();
433 434
	}
434 435

  
435 436
	/*
b/src/gr/ebs/gss/server/ejb/ExternalAPIRemote.java
190 190
	 * @param userId the ID of the current user
191 191
	 * @param folderId the ID of the folder to retrieve
192 192
	 * @param folderName
193
	 * @return the updated folder
193 194
	 * @throws InsufficientPermissionsException if the user does not have the
194 195
	 *             appropriate privileges
195 196
	 * @throws ObjectNotFoundException if the user or folder was not found, with
......
197 198
	 * @throws DuplicateNameException if the specified name already exists in
198 199
	 *             the parent folder, as either a folder or file
199 200
	 */
200
	public void modifyFolder(Long userId, Long folderId, String folderName) throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException;
201
	public FolderDTO modifyFolder(Long userId, Long folderId, String folderName) throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException;
201 202

  
202 203
	/**
203 204
	 * Adds a user to the specified group
b/src/gr/ebs/gss/server/rest/FilesHandler.java
1209 1209
	 * @throws IOException if an input/output error occurs
1210 1210
	 */
1211 1211
	private void updateResource(HttpServletRequest req, HttpServletResponse resp, String path) throws IOException {
1212
		User user = getUser(req);
1212
		final User user = getUser(req);
1213 1213
		User owner = getOwner(req);
1214 1214
		Object resource = null;
1215 1215
		try {
......
1234 1234
			if (logger.isDebugEnabled())
1235 1235
				logger.debug("JSON update: " + json);
1236 1236
			if (resource instanceof FolderDTO) {
1237
				FolderDTO folder = (FolderDTO) resource;
1237
				final FolderDTO folder = (FolderDTO) resource;
1238 1238
				String name = json.optString("name");
1239 1239
				if (!name.isEmpty()){
1240 1240
					try {
......
1243 1243
						resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
1244 1244
						return;
1245 1245
					}
1246
					getService().modifyFolder(user.getId(), folder.getId(), name);
1247
					FolderDTO folderUpdated = getService().getFolder(user.getId(), folder.getId());
1246
					final String fName = name;
1247
					FolderDTO folderUpdated = new TransactionHelper<FolderDTO>().tryExecute(new Callable<FolderDTO>() {
1248
						@Override
1249
						public FolderDTO call() throws Exception {
1250
							return getService().modifyFolder(user.getId(), folder.getId(), fName);
1251
						}
1252

  
1253
					});
1248 1254
					String parentUrl =URLDecoder.decode(getContextPath(req, true),"UTF-8");
1249 1255
					String fpath = URLDecoder.decode(req.getPathInfo(), "UTF-8");
1250 1256
					parentUrl = parentUrl.replaceAll(fpath, "");
......
1256 1262

  
1257 1263
				JSONArray permissions = json.optJSONArray("permissions");
1258 1264
				if (permissions != null) {
1259
					Set<PermissionDTO> perms = parsePermissions(user, permissions);
1260
					getService().setFolderPermissions(user.getId(), folder.getId(), perms);
1265
					final Set<PermissionDTO> perms = parsePermissions(user, permissions);
1266
					new TransactionHelper<Object>().tryExecute(new Callable<Object>() {
1267
						@Override
1268
						public Object call() throws Exception {
1269
							getService().setFolderPermissions(user.getId(), folder.getId(), perms);
1270
							return null;
1271
						}
1272

  
1273
					});
1261 1274
				}
1262 1275
			} else {
1263
				FileHeaderDTO file = (FileHeaderDTO) resource;
1276
				final FileHeaderDTO file = (FileHeaderDTO) resource;
1264 1277
				String name = null;
1265 1278
				if (json.opt("name") != null)
1266 1279
					name = json.optString("name");
1267 1280
				JSONArray tagset = json.optJSONArray("tags");
1268
				String tags = null;
1281
				String tags= null;
1269 1282
				StringBuffer t = new StringBuffer();
1270 1283
				if (tagset != null) {
1271 1284
					for (int i = 0; i < tagset.length(); i++)
1272 1285
						t.append(tagset.getString(i) + ',');
1273 1286
					tags = t.toString();
1274 1287
				}
1275
				if (name != null || tags != null)
1276
					getService().updateFile(user.getId(), file.getId(), name, tags);
1288
				if (name != null || tags != null) {
1289
					final String fName = name;
1290
					final String fTags = tags;
1291
					new TransactionHelper<Object>().tryExecute(new Callable<Object>() {
1292
						@Override
1293
						public Object call() throws Exception {
1294
							getService().updateFile(user.getId(), file.getId(), fName, fTags);
1295
							return null;
1296
						}
1297

  
1298
					});
1299
				}
1277 1300

  
1278 1301
				JSONArray permissions = json.optJSONArray("permissions");
1279 1302
				Set<PermissionDTO> perms = null;
......
1282 1305
				Boolean readForAll = null;
1283 1306
				if (json.opt("readForAll") != null)
1284 1307
					readForAll = json.optBoolean("readForAll");
1285
				if (perms != null || readForAll != null)
1286
					getService().setFilePermissions(user.getId(), file.getId(), readForAll, perms);
1308
				if (perms != null || readForAll != null) {
1309
					final Boolean fReadForAll = readForAll;
1310
					final Set<PermissionDTO> fPerms = perms;
1311
					new TransactionHelper<Object>().tryExecute(new Callable<Object>() {
1312
						@Override
1313
						public Object call() throws Exception {
1314
							getService().setFilePermissions(user.getId(), file.getId(), fReadForAll, fPerms);
1315
							return null;
1316
						}
1317

  
1318
					});
1319
				}
1287 1320

  
1288 1321
				if (json.opt("versioned") != null) {
1289
					boolean versioned = json.getBoolean("versioned");
1290
					getService().toggleFileVersioning(user.getId(), file.getId(), versioned);
1322
					final boolean versioned = json.getBoolean("versioned");
1323
					new TransactionHelper<Object>().tryExecute(new Callable<Object>() {
1324
						@Override
1325
						public Object call() throws Exception {
1326
							getService().toggleFileVersioning(user.getId(), file.getId(), versioned);
1327
							return null;
1328
						}
1329

  
1330
					});
1291 1331
				}
1292 1332
			}
1293 1333
		} catch (JSONException e) {
......
1300 1340
			resp.sendError(HttpServletResponse.SC_CONFLICT, e.getMessage());
1301 1341
		} catch (RpcException e) {
1302 1342
			resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path);
1343
		} catch (Exception e) {
1344
			resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path);
1345
			return;
1303 1346
		}
1304 1347
	}
1305 1348

  
......
1354 1397
	 * @param folderName the name of the new folder
1355 1398
	 * @throws IOException if an input/output error occurs
1356 1399
	 */
1357
	private void createFolder(HttpServletRequest req, HttpServletResponse resp, String path, String folderName) throws IOException {
1400
	private void createFolder(HttpServletRequest req, HttpServletResponse resp, String path, final String folderName) throws IOException {
1358 1401
		if (logger.isDebugEnabled())
1359 1402
   			logger.debug("Creating folder " + folderName + " in '" + path);
1360 1403

  
1361
    	User user = getUser(req);
1404
    	final User user = getUser(req);
1362 1405
    	User owner = getOwner(req);
1363 1406
        boolean exists = true;
1364 1407
        try {
......
1389 1432
		}
1390 1433
		try {
1391 1434
			if (parent instanceof FolderDTO) {
1392
				FolderDTO folder = (FolderDTO) parent;
1393
				getService().createFolder(user.getId(), folder.getId(), folderName);
1435
				final FolderDTO folder = (FolderDTO) parent;
1436
				new TransactionHelper<Object>().tryExecute(new Callable<Object>() {
1437
					@Override
1438
					public Object call() throws Exception {
1439
						getService().createFolder(user.getId(), folder.getId(), folderName);
1440
						return null;
1441
					}
1442

  
1443
				});
1394 1444
	        	String newResource = getContextPath(req, true) + folderName;
1395 1445
	        	resp.setHeader("Location", newResource);
1396 1446
	        	resp.setContentType("text/plain");
......
1412 1462
		} catch (RpcException e) {
1413 1463
			resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path + folderName);
1414 1464
			return;
1465
		} catch (Exception e) {
1466
        	resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path);
1467
			return;
1415 1468
		}
1416 1469
    	resp.setStatus(HttpServletResponse.SC_CREATED);
1417 1470
	}

Also available in: Unified diff