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

com.github.matheusesoft.alm.api.model.Test Maven / Gradle / Ivy

The newest version!
package com.github.matheusesoft.alm.api.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "Entity")
@XmlAccessorType(XmlAccessType.FIELD)
public class Test
{
	@XmlElement(name = "Field", required = true)
    @XmlElementWrapper(name = "Fields")
    private List fields;

    @XmlAttribute(name = "Type", required = true)
    private String type;
    
    public Test(Entity entity)
    {
    	this.fields = entity.fields();
        this.type = entity.type();
    }

    public Test()
    {
        type("test");
    }

    public String execStatus()
    {
        return fieldValue("exec-status");
    }

    public void execStatus(String value)
    {
        fieldValue("exec-status", value);
    }

    public String owner()
    {
        return fieldValue("owner");
    }

    public void owner(String value)
    {
        fieldValue("owner", value);
    }

    public String status()
    {
        return fieldValue("status");
    }

    public void status(String value)
    {
        fieldValue("status", value);
    }

    public String subtypeId()
    {
        return fieldValue("subtype-id");
    }

    public void subtypeId(String value)
    {
        fieldValue("subtype-id", value);
    }

    public String description()
    {
        return fieldValue("description");
    }

    public void description(String value)
    {
        fieldValue("description", value);
    }
    
    public List fields()
    {
        if (fields == null)
        {
            fields = new ArrayList();
        }

        return fields;
    }

    public String type()
    {
        return type;
    }

    public void type(String value)
    {
        type = value;
    }

    public Field field(String name)
    {
        for (Field field: fields())
        {
            if (name.equals(field.name()))
            {
                return field;
            }
        }

        return null;
    }

    public void removeField(String name)
    {
        Iterator it = fields().iterator();

        while (it.hasNext())
        {
            Field field = it.next();

            if (name.equals(field.name()))
            {
                it.remove();
            }
        }
    }

    public void clearBeforeUpdate()
    {
        removeField("id");
    }

    public String fieldValue(String name)
    {
        Field field = field(name);

        return field != null ? field.value() : null;
    }

    public void fieldValue(String name, String value)
    {
        Field field = field(name);

        if (field == null)
        {
            field = new Field(name);
            fields().add(field);
        }

        field.value(value);
    }

    public String id()
    {
        return fieldValue("id");
    }

    public void id(String value)
    {
        fieldValue("id", value);
    }

    public String parentId()
    {
        return fieldValue("parent-id");
    }

    public void parentId(String value){
        fieldValue("parent-id", value);
    }

    public String name(){
        return fieldValue("name");
    }

    public void name(String value){
        fieldValue("name", value);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy