org.opentestsystem.delivery.testreg.domain.MasterResourceAccommodation.java Source code

Java tutorial

Introduction

Here is the source code for org.opentestsystem.delivery.testreg.domain.MasterResourceAccommodation.java

Source

/*************************************************************************
 * Educational Online Test Delivery System
 * Copyright (c) 2015 American Institutes for Research
 *
 * Distributed under the AIR Open Source License, Version 1.0
 * See accompanying file AIR-License-1_0.txt or at 
 * http://www.smarterapp.org/documents/American_Institutes_for_Research_Open_Source_Software_License.pdf
 *************************************************************************/

package org.opentestsystem.delivery.testreg.domain;

import static org.apache.commons.lang.StringUtils.isNotEmpty;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

@Document
@JsonIgnoreProperties(ignoreUnknown = true)
public class MasterResourceAccommodation implements Serializable {
    private static final long serialVersionUID = 6724376115476476492L;

    @Id
    private String id;

    @NotBlank
    private String code;

    @NotBlank
    private int order;

    private boolean disabled;

    private String defaultSelection;

    private List<AccommodationText> header;

    @NotBlank
    private String resourceType;

    private List<AccommodationOption> options = new ArrayList<AccommodationOption>();

    public static final class AccommodationOption {
        private String code;
        private int order;
        private boolean mutuallyExclusive;
        private List<AccommodationText> text;

        /**
         * @param code
         * @param order
         * @param mutuallyExclusive
         * @param text
         */
        public AccommodationOption(String code, int order, boolean mutuallyExclusive,
                List<AccommodationText> text) {
            super();
            this.code = code;
            this.order = order;
            this.mutuallyExclusive = mutuallyExclusive;
            this.text = text;
        }

        public AccommodationOption() {

        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public int getOrder() {
            return order;
        }

        public void setOrder(int order) {
            this.order = order;
        }

        public boolean isMutuallyExclusive() {
            return mutuallyExclusive;
        }

        public void setMutuallyExclusive(boolean mutuallyExclusive) {
            this.mutuallyExclusive = mutuallyExclusive;
        }

        public List<AccommodationText> getText() {
            return text;
        }

        public void setText(List<AccommodationText> text) {
            this.text = text;
        }

        @Override
        public int hashCode() {
            return com.google.common.base.Objects.hashCode(this.code);
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            AccommodationOption other = (AccommodationOption) obj;
            if (code == null) {
                if (other.code != null)
                    return false;
            } else if (!code.equals(other.code))
                return false;
            return true;
        }

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

    public String getDefaultSelection() {
        return defaultSelection;
    }

    public void setDefaultSelection(String defaultSelection) {
        this.defaultSelection = defaultSelection;
    }

    public List<AccommodationText> getHeader() {
        return header;
    }

    public void setHeader(List<AccommodationText> header) {
        this.header = header;
    }

    public AccommodationResourceType getResourceType() {
        if (isNotEmpty(this.resourceType)) {
            return AccommodationResourceType.valueOf(this.resourceType);
        }
        throw new IllegalArgumentException("Invalid resourceType");
    }

    @JsonProperty
    public void setResourceType(final String resourceType) {
        if (isNotEmpty(resourceType)) {
            this.resourceType = Character.toTitleCase(resourceType.charAt(0))
                    + resourceType.substring(1).toLowerCase();
        } else {

            this.resourceType = resourceType;
        }
    }

    public List<AccommodationOption> getOptions() {
        return options;
    }

    public void setOptions(List<AccommodationOption> options) {
        this.options = options;
    }

}