1 package org.kuali.student.enrollment.class1.lpr.service.utilities;
2
3 import org.kuali.student.enrollment.class1.lpr.model.LprAttributeEntity;
4 import org.kuali.student.enrollment.class1.lpr.model.LprEntity;
5 import org.kuali.student.r2.common.dto.AttributeInfo;
6 import org.springframework.transaction.annotation.Transactional;
7
8 import javax.persistence.EntityManager;
9 import java.util.Calendar;
10 import java.util.HashSet;
11 import java.util.Set;
12
13 import static org.kuali.student.enrollment.class1.lpr.service.utilities.Constants.DA_KEY_1;
14 import static org.kuali.student.enrollment.class1.lpr.service.utilities.Constants.DA_KEY_2;
15 import static org.kuali.student.enrollment.class1.lpr.service.utilities.Constants.DA_VALUE_1;
16 import static org.kuali.student.enrollment.class1.lpr.service.utilities.Constants.DA_VALUE_2;
17 import static org.kuali.student.enrollment.class1.lpr.service.utilities.Constants.LUI_ID1;
18 import static org.kuali.student.enrollment.class1.lpr.service.utilities.Constants.PERSON_ID1;
19 import static org.kuali.student.enrollment.class1.lpr.service.utilities.Constants.TEST_VALUE_1;
20
21
22
23
24 public class DataLoader {
25
26 private EntityManager em;
27
28 @Transactional
29 public void load() {
30 LprEntity luiPersonRelation = createLuiPersonRelation();
31 em.persist(luiPersonRelation);
32 }
33
34 private LprEntity createLuiPersonRelation() {
35 LprEntity personRelation = new LprEntity();
36 personRelation.setLuiId(LUI_ID1);
37 personRelation.setPersonId(PERSON_ID1);
38 personRelation.setEffectiveDate(Calendar.getInstance().getTime());
39 personRelation.setExpirationDate(Calendar.getInstance().getTime());
40 personRelation.setPersonRelationStateId(TEST_VALUE_1);
41 personRelation.setPersonRelationTypeId(TEST_VALUE_1);
42 personRelation.setAttributes(createAttributes(personRelation));
43 return personRelation;
44 }
45
46
47 private Set<LprAttributeEntity> createAttributes(LprEntity personRelation) {
48 Set<LprAttributeEntity> attributes = new HashSet<LprAttributeEntity>();
49
50 attributes.add (new LprAttributeEntity(new AttributeInfo(DA_KEY_1, DA_VALUE_1), personRelation));
51 attributes.add (new LprAttributeEntity(new AttributeInfo(DA_KEY_2, DA_VALUE_2), personRelation));
52
53 return attributes;
54 }
55
56
57 public void setEm(EntityManager em) {
58 this.em = em;
59 }
60 }