SecurityObjectVO.java

/*
 * Copyright 2005-2025 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 org.openwms.core.uaa.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import jakarta.validation.constraints.NotBlank;
import org.ameba.http.AbstractBase;

import java.io.Serializable;
import java.util.Objects;

/**
 * A SecurityObjectVO encapsulates common attributes of roles and grants.
 *
 * @author Heiko Scherrer
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public class SecurityObjectVO<T extends SecurityObjectVO<T>> extends AbstractBase<T> implements Serializable {

    /** HTTP media type representation. */
    public static final String MEDIA_TYPE = "application/vnd.openwms.uaa.security-object-v1+json";

    /** The persistent key. */
    @JsonProperty("pKey")
    private String pKey;
    /** Unique name of the SecurityObject. */
    @JsonProperty("name")
    @NotBlank(groups = {ValidationGroups.Create.class, ValidationGroups.Modify.class})
    private String name;
    /** A descriptive text for the SecurityObject. */
    @JsonProperty("description")
    private String description;

    /*~-------------------- constructors --------------------*/
    @JsonCreator
    public SecurityObjectVO() {
        // NOT for the mapper
    }

    /*~-------------------- accessors --------------------*/
    public String getpKey() {
        return pKey;
    }

    public void setpKey(String pKey) {
        this.pKey = pKey;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    /*~-------------------- methods --------------------*/
    /**
     * {@inheritDoc}
     *
     * All fields.
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        var that = (SecurityObjectVO) o;
        return Objects.equals(name, that.name) &&
                Objects.equals(description, that.description);
    }

    /**
     * {@inheritDoc}
     *
     * All fields.
     */
    @Override
    public int hashCode() {
        return Objects.hash(name, description);
    }

    /**
     * {@inheritDoc}
     *
     * Name only.
     */
    @Override
    public String toString() {
        return name;
    }
}