com.intuit.tank.project.ExternalScript.java Source code

Java tutorial

Introduction

Here is the source code for com.intuit.tank.project.ExternalScript.java

Source

package com.intuit.tank.project;

/*
 * #%L
 * Intuit Tank data model
 * %%
 * Copyright (C) 2011 - 2015 Intuit Inc.
 * %%
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * #L%
 */

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.envers.Audited;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Audited
@Table(name = "external_script")
public class ExternalScript extends OwnableEntity implements Comparable<ExternalScript> {

    private static final long serialVersionUID = 1L;

    @Column(name = "name", length = 255, nullable = false)
    @NotEmpty
    @Length(max = 255)
    private String name;

    @Column(name = "script")
    @Lob
    private String script;

    @Column(name = "product_name", length = 255)
    @Length(max = 255)
    private String productName;

    public String getName() {
        return name;
    }

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

    /**
     * @return the script
     */
    public String getScript() {
        return script;
    }

    /**
     * @param script
     *            the script to set
     */
    public void setScript(String script) {
        this.script = script;
    }

    /**
     * @return the productName
     */
    public String getProductName() {
        return productName;
    }

    /**
     * @param productName
     *            the productName to set
     */
    public void setProductName(String productName) {
        this.productName = productName;
    }

    public ScriptEngine getEngine() {
        return new ScriptEngineManager().getEngineByExtension(FilenameUtils.getExtension(name));
    }

    /**
     * @{inheritDoc
     */
    @Override
    public String toString() {
        return new ToStringBuilder(this).append("id", getId()).append("name", name).toString();
    }

    /**
     * @{inheritDoc
     */
    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ExternalScript)) {
            return false;
        }
        ExternalScript o = (ExternalScript) obj;
        return new EqualsBuilder().append(o.getId(), getId()).isEquals();
    }

    /**
     * @{inheritDoc
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder(39, 41).append(getId()).toHashCode();
    }

    /**
     * @{inheritDoc
     */
    @Override
    public int compareTo(ExternalScript o) {
        return name.compareToIgnoreCase(o.getName());
    }
}