Skip to content

Instantly share code, notes, and snippets.

View samuelmale's full-sized avatar
🏠
Working from home

Samuel Male samuelmale

🏠
Working from home
View GitHub Profile
@samuelmale
samuelmale / CriteriaUtils.java
Created September 12, 2018 06:04 — forked from brunocribeiro/CriteriaUtils.java
Utility method to get SQL from Hibernate Criteria
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.Criteria;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.CriteriaImpl;
import org.hibernate.internal.SessionImpl;
import org.hibernate.loader.OuterJoinLoader;
import org.hibernate.loader.criteria.CriteriaLoader;
import org.hibernate.persister.entity.OuterJoinLoadable;
<?xml version='1.0' encoding='UTF-8'?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.
package org.openmrs.api.db.hibernate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.poi.util.SystemOutLogger;
import org.junit.Assert;
import org.junit.Before;
// We created our link dynamically from here
@Override
public Map<String, String> getLinks() {
Map<String, String> links = new HashMap<String, String>();
if (ModuleUtil.compareVersion(OpenmrsConstants.OPENMRS_VERSION, DIAGNOSIS_MIGRATION_LEAST_SUPPORTED_VERSION) >= 0) {
links.put("module/emrapi/MigrateDiagnosis.form", Context.getMessageSourceService().getMessage("emrapi.migrateDiagnosis.migrateDiagnosisLink.name"));
}
return links;
}
// this works fine
if (!fields.isEmpty()) {
Criteria crit2 = crit.createCriteria("formFields", "ff");
crit2.add(Restrictions.eqProperty("ff.form.formId", "f.formId"));
crit2.add(Restrictions.in("ff.field", fields));
}
// this also works fine
if (!fields.isEmpty()) {
/**
* This is a utility class that gives convenience methods for cryptography
* I actually wrote this class to help out a friend @clyne
*
* @author Samuel Male
*/
public class EncrptionUtils {
/**
* It does the Encryption. It actually delegates {@link #encrypt(String, String, Operation)} internally.
<?xml version="1.0" encoding="UTF-8"?>
<PurcForm><Xform><xf:xforms xmlns:xf="http://www.w3.org/2002/xforms" xmlns:jr="http://openrosa.org/javarosa" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><parsererror xmlns="http://www.w3.org/1999/xhtml" style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"><h3>This page contains the following errors:</h3><div style="font-family:monospace;font-size:12px">error on line 4 at column 116: xmlns:openmrs: 'formentry.infopath_server_url cannot be empty/moduleServlet/formentry/forms/schema/17-1' is not a valid URI
</div><h3>Below is a rendering of the page up to the first error.</h3></parsererror>
<xf:model id="openmrs_model">
<xf:instance id="openmrs_model_instance">
<form xmlns:openmrs="formentry.infopath_server_url cannot be empty/moduleServlet/formentry/forms/schema/17-1" xmlns:xd="http://schemas.microsoft.com/office/infopath/20
<?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.module.idgen" >
<class name="IdentifierSource" table="idgen_identifier_source" abstract="true" discriminator-value="IDENTIFIERSOURCE">
<id name="id" type="int" column="id" unsaved-value="0"><generator class="native" /></id>
<property name="uuid" type="string" length="38" not-null="true" />
<property name="name" type="string" not-null="true" />
<property name="description" type="string" />
<?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.module.idgen" >
<class name="IdentifierSource" table="idgen_identifier_source" abstract="true" >
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native" />
</id>
<discriminator column="source_type" />
<property name="uuid" type="string" length="38" not-null="true" />
@PostMapping("safebusiness/addAct/{string}")
public String addAct(@Valid Act act, @PathVariable("string") String action, HttpServletRequest httpRequest) {
try {
// Try parsing id
Integer id = Integer.parseInt(action);
// If we reach this point, then we must be dealing with an update operation
// Pull the existing Act
act = actRepo.findById(id);
// act.setId(); NOTE : This should not be done while updating
Map<String, String[]> formData = httpRequest.getParameterMap();