All Downloads are FREE. Search and download functionalities are using the official Maven repository.

base.jee.api.cassandra.UpsertGroupRole Maven / Gradle / Ivy

/**
 * Creative commons Attribution-NonCommercial license.
 *
 * http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB
 *
 * NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 */
package base.jee.api.cassandra;

import base.Command;
import base.jee.Constants;
import base.json.Json;
import base.security.PermissionException;
import base.security.User;

import java.io.IOException;
import java.util.UUID;

public class UpsertGroupRole extends Command {

	private CassandraAPI c;
	private User user;
	private UUID groupUuid;
	private String role;

	public UpsertGroupRole(CassandraAPI c, User user, UUID groupUuid, String role) throws PermissionException {
		this.c = c;
		this.groupUuid = groupUuid;
		this.role = role;
		this.user = user;

		if(c == null) {
			throw new IllegalArgumentException("Invalid parameter: c");
		}
		if(role == null || role.length() == 0) {
			throw new IllegalArgumentException("Invalid parameter: role");
		}
		if(user == null) {
			throw new PermissionException(this.getClass().getSimpleName(), user, "You do not have permission to manage this persons roles.", Constants.GROUP_MANAGE_ROLE, "Group", "" + groupUuid.toString());
		}
		if(groupUuid == null) {
			throw new IllegalArgumentException("Invalid parameter: groupUuid");
		}

		if(role.trim().length() > Constants.MAX_ROLE_NAME_LENGTH) {
			throw new IllegalArgumentException("Role names should not have more than " + Constants.MAX_ROLE_NAME_LENGTH + " characters.");
		}

	}

	public UpsertGroupRole() {
	}

	@Override
	protected void execute() throws IOException {
		throw new IllegalStateException("Unimplemented");
	}

	@Override
	public String getJsonParameters() {
		return "{" +
				"\"requestor.uuid\":\"" + user.getPersonUuid() + "\"," +
				"\"group.uuid\":\"" + groupUuid + "\"," +
				"\"role\":\"" + Json.escape(role) + "\"" +
				"}";
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy