Skip to content

Commit

Permalink
TRUNK-4286: OrderType classes, xml and hibernate configuration added
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Szell authored and wluyima committed Mar 5, 2014
1 parent f94a2c2 commit eb8f6a3
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 0 deletions.
158 changes: 158 additions & 0 deletions api/src/main/java/org/openmrs/OrderType.java
@@ -0,0 +1,158 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.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://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs;

import java.util.Collection;

/**
* OrderType
*/
public class OrderType extends BaseOpenmrsMetadata implements java.io.Serializable {

public static final long serialVersionUID = 23232L;

// Fields

private Integer orderTypeId;

private String javaClass;

private OrderType parent;

private Collection<ConceptClass> conceptClasses;

// Constructors

/**
* default constructor
*/
public OrderType() {
}

/**
* Constructor with ID
*
* @param orderTypeId the ID of the {@link org.openmrs.OrderType}
*/
public OrderType(Integer orderTypeId) {
this.orderTypeId = orderTypeId;
}

/**
* Convenience constructor that takes in the elements required to save this OrderType to the
* database
*
* @param name The name of this order Type
* @param description A short description about this order type
*/
public OrderType(String name, String description, Class javaClass) {
setName(name);
setDescription(description);
setJavaClass(javaClass.toString());
}

// Property accessors

/**
* @return Returns the orderTypeId.
*/
public Integer getOrderTypeId() {
return orderTypeId;
}

/**
* @param orderTypeId The orderTypeId to set.
*/
public void setOrderTypeId(Integer orderTypeId) {
this.orderTypeId = orderTypeId;
}

/**
* @see org.openmrs.OpenmrsObject#getId()
* @since 1.5
*/
public Integer getId() {
return getOrderTypeId();
}

/**
* @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
* @since 1.5
*/
public void setId(Integer id) {
setOrderTypeId(id);

}

/**
* @return Returns the Java class as String
*/
public String getJavaClass() {
return javaClass;
}

/**
* Same as the {@link org.openmrs.OrderType#getJavaClass()}, but it returns a {@link java.lang.Class} for convenience
*
* @return The Java class as {@link java.lang.Class}
* @throws ClassNotFoundException
*/
public Class getJavaClassAsClass() throws ClassNotFoundException {
return Class.forName(javaClass);
}

/**
* @param javaClass The Java class to set as String
*/
public void setJavaClass(String javaClass) {
this.javaClass = javaClass;
}

/**
* Same as the {@link org.openmrs.OrderType#setJavaClass(String)}, but it takes a {@link java.lang.Class} for convenience
*
* @param javaClass The Java class to set
*/
public void setJavaClass(Class javaClass) {
this.javaClass = javaClass.getName();
}

/**
* @return Returns the {@link org.openmrs.OrderType}
*/
public OrderType getParent() {
return parent;
}

/**
* @param parent The {@link org.openmrs.OrderType} to set
*/
public void setParent(OrderType parent) {
this.parent = parent;
}

/**
* @return Get the {@link org.openmrs.ConceptClass}es
*/
public Collection<ConceptClass> getConceptClasses() {
return conceptClasses;
}

/**
* @param conceptClasses the collection containing the {@link org.openmrs.ConceptClass}es
*/
public void setConceptClasses(Collection<ConceptClass> conceptClasses) {
this.conceptClasses = conceptClasses;
}
}
1 change: 1 addition & 0 deletions api/src/main/resources/hibernate.cfg.xml
Expand Up @@ -73,6 +73,7 @@
<mapping resource="org/openmrs/api/db/hibernate/RelationshipType.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Order.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/CareSetting.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/OrderType.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Location.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/LocationTag.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/LocationAttributeType.hbm.xml" />
Expand Down
@@ -0,0 +1,51 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.openmrs">

<class name="OrderType" table="order_type">

<id name="orderTypeId" type="int" column="order_type_id" unsaved-value="0">
<generator class="native">
<param name="sequence">order_type_order_type_id_seq</param>
</generator>
</id>

<discriminator column="order_type_id" insert="false"/>

<property name="name" type="java.lang.String"
not-null="true" length="255"/>

<property name="description" type="java.lang.String"
not-null="true" length="1024"/>

<property name="javaClass" type="java.lang.String"
not-null="true" length="1024"/>

<many-to-one name="parent" class="OrderType"/>

<many-to-one name="creator" class="User" not-null="true"/>

<property name="dateCreated" type="java.util.Date"
column="date_created" not-null="true" length="19"/>

<property name="retired" type="boolean" column="retired"
length="1" not-null="true"/>

<property name="dateRetired" type="java.util.Date"
column="date_retired" length="19"/>

<many-to-one name="retiredBy" class="User" column="retired_by"/>

<property name="uuid" type="java.lang.String"
column="uuid" length="38" unique="true" not-null="true"/>

<set name="conceptClasses">
<key column="order_type_id"/>
<one-to-many class="ConceptClass" entity-name="concept_class"/>
</set>

</class>

</hibernate-mapping>
46 changes: 46 additions & 0 deletions api/src/test/java/org/openmrs/OrderTypeTest.java
@@ -0,0 +1,46 @@
package org.openmrs;

import org.junit.Assert;
import org.junit.Test;
import org.openmrs.test.Verifies;

/**
* This class tests all methods that are not getter or setters in the {@link org.openmrs.OrderType} java object
* this test class for {@link org.openmrs.OrderType}
*
* @see org.openmrs.OrderType
*/
public class OrderTypeTest {

/**
* @see org.openmrs.OrderType#setJavaClass(Class)
*/
@Test
@Verifies(value = "should set java class as String", method = "setJavaClass(Class)")
public void setJavaClass_shouldSetJavaClassAsString() throws Exception {
//Create a new OrderType
OrderType orderType = new OrderType();

//Test with Integer class
Class clazz = Integer.class;

orderType.setJavaClass(clazz);
Assert.assertEquals("java.lang.Integer", orderType.getJavaClass());
}

/**
* @see OrderType#getJavaClassAsClass()
*/
@Test
@Verifies(value = "should get java class String as class", method = "getJavaClassAsClass()")
public void setJavaClass_shouldGetJavaClassStringAsClass() throws Exception {
//Create a new OrderType
OrderType orderType = new OrderType();

//Test with Integer class
Class clazz = Integer.class;

orderType.setJavaClass(clazz.getName());
Assert.assertEquals(clazz, orderType.getJavaClassAsClass());
}
}

0 comments on commit eb8f6a3

Please sign in to comment.