Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dk.dkma.fee.gopro.gdf;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.StringTokenizer;
- import java.util.Map.Entry;
- import net.gopro.axis.services.client.DocumentService;
- import net.gopro.exceptions.GoProException;
- import net.gopro.gdf.data.BinaryFilterExpressionType;
- import net.gopro.gdf.data.DisjunctionListType;
- import net.gopro.gdf.data.DocumentFilterType;
- import net.gopro.gdf.data.FlexibleDataRowType;
- import net.gopro.gdf.data.FlexibleDataSetResultType;
- import net.gopro.gdf.data.FlexibleDataSetType;
- import net.gopro.gdf.data.types.DeleteStatusType;
- import net.gopro.gdf.data.types.FilterOperatorType;
- import net.gopro.gdf.data.types.HiddenStatusType;
- import net.gopro.gdf.services.IBaseDocumentService;
- import net.gopro.tenzing.services.DocumentTypes;
- import net.gopro.tenzing.services.FilterProps;
- import net.gopro.tenzing.util.PropertyNamingUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import dk.dkma.fee.dao.ISettingsDAO;
- import dk.dkma.fee.dao.ISubjectWordDAO;
- import dk.dkma.fee.domain.Case;
- import dk.dkma.fee.domain.CaseObject;
- import dk.dkma.fee.domain.Settings;
- import dk.dkma.fee.domain.SubjectWord;
- import dk.dkma.fee.domain.CaseObject.OType;
- import dk.dkma.fee.entity.Emneord;
- import dk.dkma.fee.exception.CaseException;
- import dk.dkma.fee.utility.logging.FeeSystemLogger;
- @Service
- public class GoProGDFServiceImpl implements IGoProGDFService {
- private static final long serialVersionUID = 1L;
- private static final FeeSystemLogger log = FeeSystemLogger.getServiceLogger();
- IBaseDocumentService service;
- @Autowired
- private ISettingsDAO settingsDAO;
- @Autowired
- private ISubjectWordDAO subjectWordDAO;
- public GoProGDFServiceImpl() {
- super();
- }
- private void init() {
- String userName = getSettingsDAO().get(Settings.GO_PRO_GDF_USERNAME);
- String password = getSettingsDAO().get(Settings.GO_PRO_GDF_PASSWORD);
- String endPoint = getSettingsDAO().get(Settings.GO_PRO_GDF_ENDPOINT);
- this.service = initiateDocumentService(userName, password, endPoint);
- log.info("GDF Service initialised successfully");
- }
- /**
- * Creates a document service that can be used for common CRUD actions for
- * every document type. The user must be a registered user in the system.
- *
- * @param userName
- * A user name for a registered user
- * @param password
- * The users password
- * @param endPoint
- * The services endpoint of the document service.
- * @return
- */
- IBaseDocumentService initiateDocumentService(String userName,
- String password, String endPoint) {
- return service = new DocumentService(endPoint, userName, password);
- }
- private enum Phase {
- FEE_COLLECTION("Gebyropkrævning");
- private String name;
- private Phase(String name) {
- this.name = name;
- }
- public String getName() {
- return this.name;
- }
- }
- /**
- * Gets the ID of the Phase element attached to the case identified by
- * caseID
- *
- * @param caseID
- * The ID of the case. This is NOT the case number, it is the actual ID
- * @return
- * The ID of the Phase element, resembles a UUID.
- */
- public String getPhaseIdFromCase(String caseID, Phase phase) {
- init();
- // Create a filter to retrieve all phases under case
- //
- final DocumentFilterType filter = new DocumentFilterType();
- filter.setLoadColumns(new String[] { FilterProps.DocumentBase.ID,
- FilterProps.DocumentBase.Subject });
- filter.setDocumentFormType(DocumentTypes.DOC_TYPE_PHASE);
- filter.setHiddenStatus(HiddenStatusType.NOTHIDDEN);
- filter.setDeleteStatus(DeleteStatusType.NOTDELETED);
- filter.setFilterParentIDs(new String[] { caseID });
- //
- // If validation is turned on for the Castor then we need to add some
- // dummy data
- // to prevent exceptions
- //
- filter.setSubject("_NO_SUBJECT_");
- filter.setID("00000000-0000-0000-0000-000000000000");
- try {
- //
- // Get the document header from the webservices
- //
- final FlexibleDataSetType documentHeaders = service
- .getDocumentHeaders(filter);
- final FlexibleDataSetResultType dataset = documentHeaders.getData();
- for (FlexibleDataRowType row : dataset.getRows()) {
- if (row.getColumnValue(1).equals(phase.getName())) {
- return row.getColumnValue(0);
- }
- }
- log.warn(String.format("Did not find phase %s from case with ID %s", phase.getName(), caseID));
- return "";
- } catch (Exception e) {
- log.error(String.format("Failed to retrieve phase %s from case with ID %s", phase.getName(), caseID), e);
- return "";
- }
- }
- public GDFCase getCaseThroughGDF(Long caseNumber) throws CaseException {
- init();
- if (caseNumber == null) {
- log.error("CaseID was not found.");
- return null;
- }
- DocumentFilterType filter = new DocumentFilterType();
- String nullId = "00000000-0000-0000-0000-000000000000";
- filter.setID(nullId);
- filter.setSubject("");
- filter.setDocumentFormType(DocumentTypes.DOC_TYPE_CASE);
- String domainObjectRefPath = getMetaPropertyFilterPath(
- DocumentTypes.DOC_TYPE_CASE, "PrimaryExtensionDoor",
- "domainObjectRef");
- // Taken from GoPro sample code
- String cassationCodePath = getMetaPropertyFilterPath(
- DocumentTypes.DOC_TYPE_CASE, "FesdPrimaryExtension",
- "GoProExtensionCassationCode");
- String[] filterColumns = new String[] { FilterProps.Case.ID,
- FilterProps.Case.FilePlanLocation_Subject,
- FilterProps.DocumentBase.Subject,
- FilterProps.Case.OrganizationUnit_Subject,
- FilterProps.Case.ResponsibleEmployee_Subject,
- FilterProps.Case.CreationDate,
- FilterProps.Case.Status_Name,
- FilterProps.Case.CompletedDate,
- FilterProps.Case.Status_Status,
- FilterProps.DocumentBase.ID,
- FilterProps.Case.Category_Subject,
- FilterProps.Case.Deadline,
- cassationCodePath,
- domainObjectRefPath,
- FilterProps.Document.Keywords };
- filter.setLoadColumns(filterColumns);
- DisjunctionListType orList = new DisjunctionListType();
- BinaryFilterExpressionType filterExpression = new BinaryFilterExpressionType();
- filterExpression.setPropertyName(FilterProps.Case.CaseNumber);
- filterExpression.setOperator(FilterOperatorType.EQUAL);
- filterExpression.setValue(String.valueOf(caseNumber));
- orList.addElement(filterExpression);
- filter.setCustomFilter(orList);
- FlexibleDataSetType documentHeaders;
- GDFCase ret = null;
- try {
- documentHeaders = service.getDocumentHeaders(filter);
- FlexibleDataSetResultType data = documentHeaders.getData();
- FlexibleDataRowType[] rows = data.getRows();
- for (int i = 0; i < rows.length; i++) {
- FlexibleDataRowType flexibleDataRowType = rows[i];
- String[] values = flexibleDataRowType.getColumnValues();
- if (values == null || values.length != 15) {
- log.error("Invalid response from GDF. Expected 15 values in response.");
- }
- String id = values[0];
- String journalKey = values[1];
- String subject = values[2];
- String organizationUnit_Subject = values[3];
- String responsibleEmployee_Subject = values[4];
- String creationDate = values[5];
- String status_Name = values[6];
- String completedDate = values[7];
- String status_Status = values[8];
- String phaseId = values[9];
- String category_Subject = values[10];
- String deadline = values[11];
- String katReference = values[12];
- String katObjects = values[13];
- String categorisation = values[14];
- ret = parseCategorisation(categorisation);
- ret.setJournalKey(journalKey);
- ret.setKATObjects(katObjects);
- ret.setPhaseId(getPhaseIdFromCase(id, Phase.FEE_COLLECTION));
- ret.setId(id);
- ret.setCaseStatus(status_Name);
- }
- } catch (GoProException e) {
- log.error(e.getLocalizedMessage());
- e.printStackTrace();
- }
- if (ret != null)
- ret.setSagsNummer(caseNumber);
- else
- throw new CaseException("Kunne ikke finde en sag i GoPro med sagsnummer " + caseNumber);
- return ret;
- }
- /**
- * This parser return a datastructure with CaseObject types mapped to the
- * values for each of these types. The OTYPE is an enum and the ArrayList
- * possibly contains multiple values returned from GoPro/KAT object
- * reference.
- *
- * @param katObjects
- * @return
- * @throws CaseException
- */
- protected HashMap<OType, ArrayList<String>> parseFagObjektReference(
- String katObjects) throws CaseException {
- if (katObjects == null) {
- return null;
- }
- HashMap<OType, ArrayList<String>> ret = new HashMap<OType, ArrayList<String>>();
- if (!katObjects.contains(CaseObject.DELIMITER_ORGANISATION)) {
- log
- .info("No Organisation was found when parsing 'fagobjekt-referencer'.");
- }
- StringTokenizer st = new StringTokenizer(katObjects, ";");
- while (st.hasMoreTokens()) {
- String str = st.nextToken();
- String type = str.substring(0, str.indexOf(":"));
- String value = str.substring(str.indexOf(":") + 1, str.length());
- if (type.equals(CaseObject.DELIMITER_DRUG)) {
- ArrayList<String> vals = ret.get(OType.DRUG);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.DRUG, vals);
- } else if (type.equals(CaseObject.DELIMITER_INSPECTION)) {
- ArrayList<String> vals = ret.get(OType.INSPECTION);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.INSPECTION, vals);
- } else if (type.equals(CaseObject.DELIMITER_ORGANISATION)) {
- ArrayList<String> vals = ret.get(OType.ORGANISATION);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.ORGANISATION, vals);
- } else if (type.equals(CaseObject.DELIMITER_ORGPROCESS)) {
- ArrayList<String> vals = ret.get(OType.ORGPROCESS);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.ORGPROCESS, vals);
- } else if (type.equals(CaseObject.DELIMITER_PACKAGE)) {
- ArrayList<String> vals = ret.get(OType.PACKAGE);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.PACKAGE, vals);
- } else if (type.equals(CaseObject.DELIMITER_PROJECT)) {
- ArrayList<String> vals = ret.get(OType.PROJECT);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.PROJECT, vals);
- } else if (type.equals(CaseObject.DELIMITER_PSUR)) {
- ArrayList<String> vals = ret.get(OType.PSUR);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.PSUR, vals);
- } else if (type.equals(CaseObject.DELIMITER_PSURGROUP)) {
- ArrayList<String> vals = ret.get(OType.PSURGROUP);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.PSURGROUP, vals);
- } else if (type.equals(CaseObject.DELIMITER_SUBPROJECT)) {
- ArrayList<String> vals = ret.get(OType.SUBPROJECT);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.SUBPROJECT, vals);
- } else if (type.equals(CaseObject.DELIMITER_SUBSTANCE)) {
- ArrayList<String> vals = ret.get(OType.SUBSTANCE);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.SUBSTANCE, vals);
- } else if (type.equals(CaseObject.DELIMITER_TRIAL)) {
- ArrayList<String> vals = ret.get(OType.TRIAL);
- if (vals == null)
- vals = new ArrayList<String>();
- vals.add(value);
- ret.put(OType.TRIAL, vals);
- }
- }
- return ret;
- }
- /**
- * Constructs the property path of a custom field to be used by creating a
- * query to the filenet. This property path can be used to define columns
- * and filters in queries to the web services.
- *
- * @param documentType
- * An integer defined by the DocumentTypes class
- * @param extensionName
- * The name of the extension in the configuration of the custom
- * fields
- * @param propertyName
- * The name of the property in the Filenet class (and not the
- * given name in the configuration of custom fields)
- * @return the property path
- */
- public static String getMetaPropertyFilterPath(int documentType,
- String extensionName, String propertyName) {
- String jointTypeName = PropertyNamingUtil.constructFilterJointTypeName(
- DocumentTypes.getDocumentTypeName(documentType), extensionName);
- String joinTypeRefName = PropertyNamingUtil
- .constructFilterJointRefTypeName(DocumentTypes
- .getDocumentTypeName(documentType), extensionName);
- String propertyPath = "_" + extensionName + "[" + joinTypeRefName + "]"
- + "._objData[" + jointTypeName + "]" + "._" + propertyName;
- return propertyPath;
- }
- /**
- * Categorisation is received in a single string. Chop this string into its
- * respectful entities and return a GDFCase object.
- *
- * @param categorisation
- * @return
- * @throws CaseException
- */
- private GDFCase parseCategorisation(String categorisation) throws CaseException {
- GDFCase cat = null;
- if (categorisation != null) {
- cat = new GDFCase();
- log.debug("Received the following categorisation from GDF: " + categorisation);
- try {
- StringTokenizer st = new StringTokenizer(categorisation, ",");
- while (st.hasMoreTokens()) {
- String nextToken = st.nextToken();
- String type = nextToken.substring(0, nextToken.indexOf("/"))
- .trim();
- String rawValue = nextToken.substring(
- nextToken.indexOf("/") + 1, nextToken.length());
- String value = rawValue.substring(
- rawValue.lastIndexOf('/') + 1, rawValue.length());
- if (type.toLowerCase().startsWith("emneord")) {
- cat.add(new Emneord(value));
- } else if (type.toLowerCase().startsWith("sundhedsaktivitet")) {
- cat.setSundhedsAktivitet(value);
- } else if (type.toLowerCase().startsWith("sundhedsprodukt")) {
- cat.setSundhedsProdukt(value);
- } else if (type.toLowerCase().startsWith("procedurerolle")) {
- cat.setProcedureRolle(value);
- } else if (type.toLowerCase().startsWith("jurisdiktion")) {
- cat.setJurisdiktion(value);
- } else if (type.toLowerCase().startsWith("forum")) {
- cat.setForum(value);
- } else if (type.toLowerCase().startsWith("sagsvolder")) {
- cat.setSagsvolder(value);
- } else if (type.toLowerCase().startsWith("opgave")) {
- cat.setOpgave(value);
- }
- }
- } catch (StringIndexOutOfBoundsException e) {
- throw new CaseException("De modtagne data fra KAT er ikke på korrekt form. Muligvis skyldes dette at sagen er af ældre dato.");
- }
- }
- return cat;
- }
- public Case convert(GDFCase cat) throws CaseException {
- Case c = new Case();
- if (cat.getKATObjects() != null && cat.getKATObjects().length() > 0) {
- HashMap<OType, ArrayList<String>> references = parseFagObjektReference(cat.getKATObjects());
- List<CaseObject> caseObjects = new ArrayList<CaseObject>();
- Iterator<Entry<OType, ArrayList<String>>> iter = references.entrySet().iterator();
- while (iter.hasNext()) {
- Entry<OType, ArrayList<String>> entry = iter.next();
- ArrayList<String> katObjects = entry.getValue();
- for (String katObject : katObjects) {
- CaseObject caseObject = new CaseObject(entry.getKey(), katObject);
- caseObjects.add(caseObject);
- }
- }
- c.setCaseObjects(caseObjects);
- }
- c.setCaseNumber(cat.getSagsNummer());
- c.setCaseId(cat.getSagsNummer());
- c.setJournalKey(cat.getJournalKey());
- c.setForum(cat.getForum());
- c.setJurisdiction(cat.getJurisdiktion());
- c.setProcedureRole(cat.getProcedureRolle());
- c.setCaseInitiator(cat.getSagsvolder());
- c.setHealthActivity(cat.getSundhedsAktivitet());
- c.setHealthProduct(cat.getSundhedsProdukt());
- c.setEmneord(cat.getEmneord());
- c.setPhaseId(cat.getPhaseId());
- c.setCaseStatus(cat.getCaseStatus());
- return c;
- }
- public void resolveEmneordToSubjectWords(Case c) {
- Iterator<Emneord> iterator = c.getEmneord().iterator();
- while (iterator.hasNext()) {
- Emneord emneord = (Emneord) iterator.next();
- String actualSubjectWordString = emneord.getValue().substring(
- emneord.getValue().lastIndexOf('/') + 1,
- emneord.getValue().length());
- List<SubjectWord> subjectWords = subjectWordDAO
- .findSubjectWordsByName(actualSubjectWordString);
- if (c.getSubjectWords() == null)
- c.setSubjectWords(new ArrayList<SubjectWord>());
- log.debug("Resolved subject word: " + subjectWords);
- c.getSubjectWords().addAll(subjectWords);
- }
- }
- public void setSettingsDAO(ISettingsDAO settingsDAO) {
- this.settingsDAO = settingsDAO;
- }
- public ISettingsDAO getSettingsDAO() {
- return settingsDAO;
- }
- }
Add Comment
Please, Sign In to add comment