agave-systems/systems-api/src/main/java/org/iplantc/service/systems/resources/BatchQueueResource.java
/**
	 * Post action for adding (and overwriting) roles on a system object
	 */
Post action for adding (and overwriting) roles on a system object
Post action for adding ( and overwriting ) roles on a system object
@Override
	public void acceptRepresentation(Representation entity)
	{
		this.username = getAuthenticatedUsername();
		AgaveLogServiceClient.log(AgaveLogServiceClient.ServiceKeys.SYSTEMS02.name(), 
				AgaveLogServiceClient.ActivityKeys.SystemBatchQueueAdd.name(), 
				username, "", getRequest().getClientInfo().getUpstreamAddress());
		try
		{
			if (StringUtils.isEmpty(systemId))
			{
				throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
						"Please specify an system using its system id. ",
						new SystemException());
			}
			RemoteSystem system = dao.findActiveAndInactiveSystemBySystemId(systemId);
			if (system == null)
			{
				throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
						"No system found matching " + systemId,
						new FileNotFoundException());
			}
			else {
				SystemRole userRole = system.getUserRole(username);
				if (!userRole.canAdmin()) {
					throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN,
							"User does not have the necessary role to edit this system.",
							new PermissionException());
				}
				else if (system.isPubliclyAvailable()) 
				{
					throw new ResourceException(Status.SERVER_ERROR_NOT_IMPLEMENTED,
							"Public system queues cannot be updated. "
							+ "Please unpublish this system before updating its queues.",
							new SystemArgumentException());
				}
			}
			SystemManager systemManager = new SystemManager();
			if (systemManager.isManageableByUser(system, username))
			{
				JSONObject json = getPostedEntityAsJsonObject(true);
				if (json == null || json.length() == 0) {
				    throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
	                        "No queue description found in the request.",
							new FileNotFoundException());
				}
				try
				{
				    BatchQueue existingQueue = null;
				    String queueName = null;
				    if (json.has("name")) 
					{
					    queueName = json.getString("name");
					    existingQueue = ((ExecutionSystem)system).getQueue(queueName);
					}
				    BatchQueue newQueue = BatchQueue.fromJSON(json, existingQueue);
					if (newQueue.isSystemDefault()) {
				        for (BatchQueue systemQueue: ((ExecutionSystem)system).getBatchQueues()) {
				            systemQueue.setSystemDefault(false);
				        }
				        newQueue.setSystemDefault(true);
				    }
					newQueue.setLastUpdated(new Date());
					dao.persist(system);
					getResponse().setEntity(new IplantSuccessRepresentation(newQueue.toJSON()));
				}
				catch (SystemArgumentException e) {
				    throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
                            e.getMessage(), e);
				}
				catch (Throwable e) {
					throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
							"An expected occurred updating system queue. "
							+ "If this persists, please contact your system admin", e);
				}
			} else {
				throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN,
						"User does not have the necessary role to modify this system queue",
						new PermissionException());
			}
		}
		catch (ResourceException e) {
			getResponse().setEntity(
					new IplantErrorRepresentation(e.getMessage()));
			getResponse().setStatus(e.getStatus());
		}
		catch (Throwable e) 
        {
		    getResponse().setEntity(
                    new IplantErrorRepresentation("Error occurred updating system queue."));
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
        }
	}
@ Override public void acceptRepresentation ( Representation entity ) { this . username = getAuthenticatedUsername ( ) ; AgaveLogServiceClient . log ( AgaveLogServiceClient . ServiceKeys . SYSTEMS02 . name ( ) , AgaveLogServiceClient . ActivityKeys . SystemBatchQueueAdd . name ( ) , username , "" , getRequest ( ) . getClientInfo ( ) . getUpstreamAddress ( ) ) ; try { if ( StringUtils . isEmpty ( systemId ) ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , "Please specify an system using its system id. " , new SystemException ( ) ) ; } RemoteSystem system = dao . findActiveAndInactiveSystemBySystemId ( systemId ) ; if ( system == null ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No system found matching " + systemId , new FileNotFoundException ( ) ) ; } else { SystemRole userRole = system . getUserRole ( username ) ; if ( ! userRole . canAdmin ( ) ) { throw new ResourceException ( Status . CLIENT_ERROR_FORBIDDEN , "User does not have the necessary role to edit this system." , new PermissionException ( ) ) ; } else if ( system . isPubliclyAvailable ( ) ) { throw new ResourceException ( Status . SERVER_ERROR_NOT_IMPLEMENTED , "Public system queues cannot be updated. " + "Please unpublish this system before updating its queues." , new SystemArgumentException ( ) ) ; } } SystemManager systemManager = new SystemManager ( ) ; if ( systemManager . isManageableByUser ( system , username ) ) { JSONObject json = getPostedEntityAsJsonObject ( true ) ; if ( json == null || json . length ( ) == 0 ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , "No queue description found in the request." , new FileNotFoundException ( ) ) ; } try { BatchQueue existingQueue = null ; String queueName = null ; if ( json . has ( "name" ) ) { queueName = json . getString ( "name" ) ; existingQueue = ( ( ExecutionSystem ) system ) . getQueue ( queueName ) ; } BatchQueue newQueue = BatchQueue . fromJSON ( json , existingQueue ) ; if ( newQueue . isSystemDefault ( ) ) { for ( BatchQueue systemQueue : ( ( ExecutionSystem ) system ) . getBatchQueues ( ) ) { systemQueue . setSystemDefault ( false ) ; } newQueue . setSystemDefault ( true ) ; } newQueue . setLastUpdated ( new Date ( ) ) ; dao . persist ( system ) ; getResponse ( ) . setEntity ( new IplantSuccessRepresentation ( newQueue . toJSON ( ) ) ) ; } catch ( SystemArgumentException e ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , e . getMessage ( ) , e ) ; } catch ( Throwable e ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "An expected occurred updating system queue. " + "If this persists, please contact your system admin" , e ) ; } } else { throw new ResourceException ( Status . CLIENT_ERROR_FORBIDDEN , "User does not have the necessary role to modify this system queue" , new PermissionException ( ) ) ; } } catch ( ResourceException e ) { getResponse ( ) . setEntity ( new IplantErrorRepresentation ( e . getMessage ( ) ) ) ; getResponse ( ) . setStatus ( e . getStatus ( ) ) ; } catch ( Throwable e ) { getResponse ( ) . setEntity ( new IplantErrorRepresentation ( "Error occurred updating system queue." ) ) ; getResponse ( ) . setStatus ( Status . SERVER_ERROR_INTERNAL ) ; } }
Post action for adding (and overwriting) roles on a system object
Post action for adding ( and overwriting ) roles on a system object
// parse the form to get the job specs