com.memority.citadel.shared.api.im.RightGrant Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of citadel-api Show documentation
Show all versions of citadel-api Show documentation
This artifact provides the API classes that are necessary to implement general configuration Rules on the Memority IM platform.
/*
* Copyright (c) 2016-2023 Memority. All Rights Reserved.
*
* This file is part of Memority Citadel API , a Memority project.
*
* This file is released under the Memority Public Artifacts End-User License Agreement,
* see
* Unauthorized copying of this file, via any medium is strictly prohibited.
*/
package com.memority.citadel.shared.api.im;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.NonNull;
import com.memority.citadel.shared.api.XmlConstants;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.*;
import static java.util.stream.Collectors.joining;
@Data
@EqualsAndHashCode(of = {"name", "target", "privilege", "computed"})
@JsonInclude(JsonInclude.Include.NON_NULL)
@XmlRootElement(name = XmlConstants.NAME_ELEMENT_RIGHT_GRANT)
@XmlType(name = XmlConstants.NAME_TYPE_RIGHT_GRANT)
@XmlAccessorType(XmlAccessType.FIELD)
public class RightGrant implements Comparable {
@JsonView(JsonViews.Jdbc.MObjectSearchQuery.class)
private final String name;
/**
* An optional resource on which the Right is granted.
*/
@XmlElement(name = "target")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonView(JsonViews.Jdbc.MObjectSearchQuery.class)
private final String target;
/**
* An optional opaque string modulating the granted Right.
* This is more intended for business fine-grained restrictions (e.g. visibility restrictions) than coarse access
* control.
*/
@XmlElement
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonView(JsonViews.Jdbc.MObjectSearchQuery.class)
private final String privilege;
@XmlElement(name = "dims")
@XmlJavaTypeAdapter(RightGrantDimensionsAdapter.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("dims")
private final Map dimensions = new HashMap<>();
@XmlAttribute(name = "computed")
@JsonProperty("computed")
private final boolean computed;
@SuppressWarnings("unused") //JAXB
private RightGrant() {
this(null, null, null, null, false);
}
public RightGrant(String name,
String target,
String privilege,
Map dimensions) {
this(name, target, privilege, dimensions, false);
}
@JsonCreator
public RightGrant(@JsonProperty("name") String name,
@JsonProperty("target") String target,
@JsonProperty("privilege") String privilege,
@JsonProperty("dims") Map dimensions,
@JsonProperty("computed") boolean computed) {
this.name = name;
this.privilege = privilege;
this.computed = computed;
this.target = target;
if (dimensions != null) {
this.dimensions.putAll(dimensions);
}
}
@Override
public int compareTo(@NonNull RightGrant o) {
return Comparator.comparing(RightGrant::getName).compare(this, o);
}
public String getName() {
return name;
}
public Map getDimensions() {
return Collections.unmodifiableMap(dimensions);
}
public Object getDimensionValue(String name) {
Object raw = this.dimensions.get(name);
if (raw == null) {
return null;
}
if (raw instanceof List) {
if (((List>) raw).isEmpty()) {
return null;
} else {
return ((List>) raw).get(0);
}
}
return raw;
}
public List