| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.student.kew.xml; |
| 17 | |
|
| 18 | |
import java.security.GeneralSecurityException; |
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.List; |
| 21 | |
|
| 22 | |
import org.apache.commons.lang.StringUtils; |
| 23 | |
import org.apache.log4j.Logger; |
| 24 | |
import org.jdom.Element; |
| 25 | |
import org.jdom.Namespace; |
| 26 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
| 27 | |
import org.kuali.rice.kew.xml.UserXmlParser; |
| 28 | |
import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo; |
| 29 | |
import org.kuali.rice.kim.impl.identity.email.EntityEmailBo; |
| 30 | |
import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo; |
| 31 | |
import org.kuali.rice.kim.impl.identity.entity.EntityBo; |
| 32 | |
import org.kuali.rice.kim.impl.identity.name.EntityNameBo; |
| 33 | |
import org.kuali.rice.kim.impl.identity.principal.PrincipalBo; |
| 34 | |
import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo; |
| 35 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
| 36 | |
import org.kuali.rice.krad.service.SequenceAccessorService; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | 0 | public class KSUserXmlParser extends UserXmlParser { |
| 43 | |
|
| 44 | 0 | protected final Logger LOG = Logger.getLogger(getClass()); |
| 45 | |
|
| 46 | 0 | private static final Namespace NAMESPACE = Namespace.getNamespace("", "ns:workflow/User"); |
| 47 | |
|
| 48 | |
private static final String WORKFLOW_ID_ELEMENT = "workflowId"; |
| 49 | |
private static final String AUTHENTICATION_ID_ELEMENT = "authenticationId"; |
| 50 | |
private static final String PRINCIPAL_ID_ELEMENT = "principalId"; |
| 51 | |
private static final String PRINCIPAL_NAME_ELEMENT = "principalName"; |
| 52 | |
private static final String EMPL_ID_ELEMENT = "emplId"; |
| 53 | |
private static final String EMAIL_ELEMENT = "emailAddress"; |
| 54 | |
private static final String GIVEN_NAME_ELEMENT = "givenName"; |
| 55 | |
private static final String LAST_NAME_ELEMENT = "lastName"; |
| 56 | |
private static final String TYPE_ELEMENT = "type"; |
| 57 | |
private static final String PASSWORD_ELEMENT = "password"; |
| 58 | |
private static final String HASH_SUFFIX = "(&^HSH#&)"; |
| 59 | |
|
| 60 | |
private static final String AFFILIATION_CD_ELEMENT = "affiliationTypeCode"; |
| 61 | |
private static final String ACTIVE_ELEMENT = "active"; |
| 62 | |
private static final String CAMPUS_CD_ELEMENT = "campusCode"; |
| 63 | |
|
| 64 | |
@Override |
| 65 | |
protected EntityBo constructEntity(Element userElement) { |
| 66 | 0 | SequenceAccessorService sas = KRADServiceLocator.getSequenceAccessorService(); |
| 67 | |
|
| 68 | 0 | String firstName = userElement.getChildTextTrim(GIVEN_NAME_ELEMENT, NAMESPACE); |
| 69 | 0 | String lastName = userElement.getChildTextTrim(LAST_NAME_ELEMENT, NAMESPACE); |
| 70 | 0 | String emplId = userElement.getChildTextTrim(EMPL_ID_ELEMENT, NAMESPACE); |
| 71 | 0 | String entityTypeCode = userElement.getChildTextTrim(TYPE_ELEMENT, NAMESPACE); |
| 72 | 0 | if (StringUtils.isBlank(entityTypeCode)) { |
| 73 | 0 | entityTypeCode = "PERSON"; |
| 74 | |
} |
| 75 | |
|
| 76 | 0 | Long entityId = sas.getNextAvailableSequenceNumber("KRIM_ENTITY_ID_S", |
| 77 | |
EntityEmploymentBo.class); |
| 78 | |
|
| 79 | |
|
| 80 | 0 | EntityEmploymentBo emplInfo = null; |
| 81 | 0 | if (!StringUtils.isBlank(emplId)) { |
| 82 | 0 | emplInfo = new EntityEmploymentBo(); |
| 83 | 0 | emplInfo.setActive(true); |
| 84 | 0 | emplInfo.setEmployeeId(emplId); |
| 85 | 0 | emplInfo.setPrimary(true); |
| 86 | 0 | emplInfo.setEntityId("" + entityId); |
| 87 | 0 | emplInfo.setId (emplId); |
| 88 | |
} |
| 89 | |
|
| 90 | |
|
| 91 | 0 | EntityBo entity = new EntityBo(); |
| 92 | |
|
| 93 | |
|
| 94 | 0 | String active = userElement.getChildTextTrim(ACTIVE_ELEMENT, NAMESPACE); |
| 95 | 0 | if("false".equals(active)){ |
| 96 | 0 | entity.setActive(false); |
| 97 | |
}else{ |
| 98 | 0 | entity.setActive(true); |
| 99 | |
} |
| 100 | |
|
| 101 | |
|
| 102 | 0 | entity.setId("" + entityId); |
| 103 | 0 | List<EntityEmploymentBo> emplInfos = new ArrayList<EntityEmploymentBo>(); |
| 104 | 0 | if (emplInfo != null) { |
| 105 | 0 | emplInfos.add(emplInfo); |
| 106 | |
} |
| 107 | 0 | entity.setEmploymentInformation(emplInfos); |
| 108 | |
|
| 109 | |
|
| 110 | 0 | String affiliationTypeCode = userElement.getChildTextTrim(AFFILIATION_CD_ELEMENT, NAMESPACE); |
| 111 | 0 | if (!StringUtils.isBlank(affiliationTypeCode)) { |
| 112 | 0 | if(entity.getAffiliations()==null){ |
| 113 | 0 | entity.setAffiliations(new ArrayList<EntityAffiliationBo>()); |
| 114 | |
} |
| 115 | 0 | EntityAffiliationBo affiliation = new EntityAffiliationBo(); |
| 116 | |
|
| 117 | 0 | Long affiliationId = sas.getNextAvailableSequenceNumber( |
| 118 | |
"KRIM_ENTITY_AFLTN_ID_S", EntityAffiliationBo.class); |
| 119 | 0 | affiliation.setId(""+affiliationId); |
| 120 | 0 | affiliation.setAffiliationTypeCode(affiliationTypeCode); |
| 121 | 0 | affiliation.setActive(true); |
| 122 | 0 | affiliation.setDefaultValue(true); |
| 123 | 0 | affiliation.setEntityId(entity.getId()); |
| 124 | 0 | String campusCode = userElement.getChildTextTrim(CAMPUS_CD_ELEMENT, NAMESPACE); |
| 125 | 0 | if(!StringUtils.isBlank(campusCode)){ |
| 126 | 0 | affiliation.setCampusCode(campusCode); |
| 127 | |
} |
| 128 | 0 | entity.getAffiliations().add(affiliation); |
| 129 | |
} |
| 130 | |
|
| 131 | 0 | EntityTypeContactInfoBo entityType = new EntityTypeContactInfoBo(); |
| 132 | 0 | entity.getEntityTypeContactInfos().add(entityType); |
| 133 | 0 | entityType.setEntityTypeCode(entityTypeCode); |
| 134 | 0 | entityType.setEntityId(entity.getId()); |
| 135 | 0 | entityType.setActive(true); |
| 136 | |
|
| 137 | 0 | if (!StringUtils.isBlank(firstName) || !StringUtils.isBlank(lastName)) { |
| 138 | 0 | Long entityNameId = sas.getNextAvailableSequenceNumber( |
| 139 | |
"KRIM_ENTITY_NM_ID_S", EntityNameBo.class); |
| 140 | 0 | EntityNameBo name = new EntityNameBo(); |
| 141 | 0 | name.setActive(true); |
| 142 | 0 | name.setId("" + entityNameId); |
| 143 | 0 | name.setEntityId(entity.getId()); |
| 144 | |
|
| 145 | 0 | name.setNameCode("PRFR"); |
| 146 | 0 | name.setFirstName(firstName); |
| 147 | 0 | name.setMiddleName(""); |
| 148 | 0 | name.setLastName(lastName); |
| 149 | 0 | name.setDefaultValue(true); |
| 150 | |
|
| 151 | 0 | entity.getNames().add(name); |
| 152 | |
} |
| 153 | |
|
| 154 | 0 | KRADServiceLocator.getBusinessObjectService().save(entity); |
| 155 | |
|
| 156 | 0 | String emailAddress = userElement.getChildTextTrim(EMAIL_ELEMENT, NAMESPACE); |
| 157 | 0 | if (!StringUtils.isBlank(emailAddress)) { |
| 158 | 0 | Long emailId = sas.getNextAvailableSequenceNumber( |
| 159 | |
"KRIM_ENTITY_EMAIL_ID_S", EntityEmailBo.class); |
| 160 | 0 | EntityEmailBo email = new EntityEmailBo(); |
| 161 | 0 | email.setActive(true); |
| 162 | 0 | email.setEntityTypeCode("PERSON"); |
| 163 | |
|
| 164 | 0 | email.setEmailTypeCode("WRK"); |
| 165 | 0 | email.setEmailAddress(emailAddress); |
| 166 | 0 | email.setDefaultValue(true); |
| 167 | 0 | email.setEntityId(entity.getId()); |
| 168 | 0 | KRADServiceLocator.getBusinessObjectService().save(email); |
| 169 | |
} |
| 170 | |
|
| 171 | 0 | return entity; |
| 172 | |
} |
| 173 | |
|
| 174 | |
@Override |
| 175 | |
protected PrincipalBo constructPrincipal(Element userElement, String entityId) { |
| 176 | 0 | String principalId = userElement.getChildTextTrim(WORKFLOW_ID_ELEMENT, NAMESPACE); |
| 177 | 0 | if (principalId == null) { |
| 178 | 0 | principalId = userElement.getChildTextTrim(PRINCIPAL_ID_ELEMENT, NAMESPACE); |
| 179 | |
} |
| 180 | 0 | String principalName = userElement.getChildTextTrim(AUTHENTICATION_ID_ELEMENT, NAMESPACE); |
| 181 | 0 | if (principalName == null) { |
| 182 | 0 | principalName = userElement.getChildTextTrim(PRINCIPAL_NAME_ELEMENT, NAMESPACE); |
| 183 | |
} |
| 184 | 0 | String password= userElement.getChildTextTrim(PASSWORD_ELEMENT, NAMESPACE); |
| 185 | |
|
| 186 | |
|
| 187 | 0 | PrincipalBo principal = new PrincipalBo (); |
| 188 | 0 | principal.setActive(true); |
| 189 | 0 | principal.setPrincipalId(principalId); |
| 190 | 0 | principal.setPrincipalName(principalName); |
| 191 | 0 | principal.setEntityId(entityId); |
| 192 | |
try { |
| 193 | 0 | principal.setPassword(CoreApiServiceLocator.getEncryptionService().hash(password)+HASH_SUFFIX); |
| 194 | 0 | } catch (GeneralSecurityException e) { |
| 195 | 0 | LOG.warn("Error hashing password.",e); |
| 196 | 0 | } |
| 197 | 0 | KRADServiceLocator.getBusinessObjectService().save(principal); |
| 198 | |
|
| 199 | 0 | return principal; |
| 200 | |
} |
| 201 | |
} |