
com.morpheusdata.model.Permission Maven / Gradle / Ivy
/*
* Copyright 2024 Morpheus Data, LLC.
*
* Licensed under the PLUGIN CORE SOURCE LICENSE (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://raw.githubusercontent.com/gomorpheus/morpheus-plugin-core/v1.0.x/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.morpheusdata.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A model for defining custom access permissions
*
* @author Mike Truso
*/
public class Permission extends MorpheusModel {
protected String name;
protected String code;
protected String subCategory;
protected List availableAccessTypes;
public String getSubCategory() {
return subCategory;
}
public void setSubCategory(String subCategory) {
this.subCategory = subCategory;
markDirty("subCategory", subCategory);
}
public enum ResourceType {
BackupRepository,
ComputeZoneFolder,
ComputeZonePool,
Datastore,
ManagedServer,
Network,
NetworkDomain,
NetworkEdgeCluster,
NetworkGroup,
NetworkLoadBalancer,
NetworkPool,
NetworkResourceGroup,
NetworkRouter,
NetworkScope,
NetworkServer,
NetworkSubnet,
PricePlan,
SecurityGroup,
ServicePlan
}
public Permission() {
//blank constructor
}
public Permission(String name, String code, List availableAccessTypes) {
this.name = name;
this.code = code;
this.availableAccessTypes = availableAccessTypes;
}
public Permission(String name, String code, List availableAccessTypes, String subCategory) {
this.name = name;
this.code = code;
this.subCategory = subCategory;
this.availableAccessTypes = availableAccessTypes;
}
public Permission(String code, List availableAccessTypes) {
this.name = code;
this.code = code;
this.availableAccessTypes = availableAccessTypes;
}
public Map asMap() {
HashMap map = new HashMap<>();
List types = this.typesAsString();
String highestType = types.get(types.size() - 1);
map.put(this.code, highestType);
return map;
}
public List typesAsString() {
List types = new ArrayList<>();
for(AccessType accessType: this.availableAccessTypes) {
types.add(accessType.name());
}
return types;
}
public static Permission build(String name, String code,String subCategory, List availableAccessTypes) {
return new Permission(name, code, availableAccessTypes,subCategory);
}
public static Permission build(String name, String code, List availableAccessTypes) {
return new Permission(name, code, availableAccessTypes);
}
public static Permission build(String code, List availableAccessTypes) {
return new Permission(code, availableAccessTypes);
}
public static Permission build(String code, String availableAccessType) {
List availableAccessTypes = new ArrayList<>();
availableAccessTypes.add(AccessType.valueOf(availableAccessType));
return new Permission(code, availableAccessTypes);
}
public List toList() {
ArrayList list = new ArrayList<>();
list.add(this);
return list;
}
public String getName() {
return name;
}
public String getCode() {
return code;
}
public List getAvailableAccessTypes() {
return availableAccessTypes;
}
public enum AccessType {
none,
read,
full
}
public void setName(String name) {
this.name = name;
markDirty("name", name);
}
public void setCode(String code) {
this.code = code;
markDirty("code", code);
}
public void setAvailableAccessTypes(List availableAccessTypes) {
this.availableAccessTypes = availableAccessTypes;
markDirty("availableAccessTypes", availableAccessTypes);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy