List of usage examples for org.springframework.dao DataAccessException getMessage
@Override
@Nullable
public String getMessage()
From source file:pe.gob.mef.gescon.hibernate.impl.ConsultaDaoImpl.java
@Override public BigDecimal countDestacadosByTipoConocimiento(HashMap filters) { String ntipoconocimientoid = ((BigDecimal) filters.get("ntipoconocimientoid")).toString(); final StringBuilder sql = new StringBuilder(); Object object = null;//ww w .j a v a 2 s . c om try { if (StringUtils.isNotBlank(ntipoconocimientoid) && ntipoconocimientoid.equals("1")) { sql.append("SELECT DISTINCT COUNT(a.nbaselegalid) AS CID "); sql.append("FROM TBASELEGAL a "); sql.append("WHERE a.nactivo = :ACTIVO "); sql.append("AND a.ndestacado = :DESTACADO "); sql.append("AND a.nestadoid IN (3,5,6) "); // Publicada, Concordada y Modificada. } if (StringUtils.isNotBlank(ntipoconocimientoid) && ntipoconocimientoid.equals("2")) { sql.append("SELECT DISTINCT COUNT(a.npreguntaid) AS CID "); sql.append("FROM TPREGUNTA a "); sql.append("WHERE a.nactivo = :ACTIVO "); sql.append("AND a.ndestacado = :DESTACADO "); sql.append("AND a.nsituacionid = 6 "); // Publicada } if (StringUtils.isNotBlank(ntipoconocimientoid) && (ntipoconocimientoid.equals("3") || ntipoconocimientoid.equals("4") || ntipoconocimientoid.equals("5") || ntipoconocimientoid.equals("6"))) { sql.append("SELECT DISTINCT COUNT(a.nconocimientoid) AS CID "); sql.append("FROM TCONOCIMIENTO a "); sql.append("WHERE a.nactivo = :ACTIVO "); sql.append("AND a.ndestacado = :DESTACADO "); sql.append("AND a.nsituacionid = 6 AND a.NTPOCONOCIMIENTOID = ").append(ntipoconocimientoid) .append(" "); // Publicado } object = getHibernateTemplate().execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { Query query = session.createSQLQuery(sql.toString()); query.setParameter("ACTIVO", BigDecimal.ONE); query.setParameter("DESTACADO", BigDecimal.ONE); return query.uniqueResult(); } }); } catch (DataAccessException e) { e.getMessage(); e.printStackTrace(); } return (BigDecimal) object; }
From source file:com.sfs.whichdoctor.dao.IsbMessageDAOImpl.java
/** * Creates the IsbMessageBean./*from w ww . j a va 2s.c o m*/ * * @param message the message * * @return the Id of the created IsbMessage if successful * * @throws WhichDoctorDaoException the which doctor dao exception */ public final int create(final IsbMessageBean message) throws WhichDoctorDaoException { int isbMessageId = 0; // Parse the ISB XML document and get the identifier // and action values for the message Element isbIdentityElement = null; try { Document isbDocument = message.getIsbPayload().getXmlDocument(); isbIdentityElement = isbDocument.getRootElement().getChild("identity"); } catch (Exception e) { dataLogger.error("Error parsing ISB XML into JDOM document: " + e.getMessage()); } // A flag whether to record the ISB message or just drop it boolean processIsbMessage = false; if (isbIdentityElement != null) { // Get the ISB identifier of this message try { message.setIdentifier(isbIdentityElement.getAttribute("id").getValue()); } catch (Exception e) { dataLogger.error("Error reading ISB XML id value: " + e.getMessage()); } // Get the ISB action of this message try { message.setAction(isbIdentityElement.getAttribute("action").getValue()); } catch (Exception e) { dataLogger.error("Error reading ISB XML action value: " + e.getMessage()); } List<?> attributes = isbIdentityElement.getChildren("attribute"); List<?> objects = isbIdentityElement.getChildren("object"); if (attributes != null && attributes.size() > 0) { processIsbMessage = true; } if (objects != null && objects.size() > 0) { processIsbMessage = true; } } if (processIsbMessage) { // At least one attribute or object is present in the ISB // message. Record the incoming message. // Set the timestamp value Timestamp creationTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis()); try { final int createCount = this.getIsbJdbcTemplate().update( this.getSQL().getValue("isbmessage/create"), new Object[] { message.getTarget(), message.getAction(), message.getSource(), message.getIdentifier(), message.getIsInbound(), message.getProcessed(), creationTimeStamp }); if (createCount > 0) { // Get the maximum id isbMessageId = this.getIsbJdbcTemplate() .queryForInt(this.getSQL().getValue("isbmessage/findMax")); // Record the ISB Payload IsbPayloadBean isbPayload = message.getIsbPayload(); isbPayload.setIsbMessageId(isbMessageId); try { this.isbPayloadDAO.create(isbPayload); } catch (WhichDoctorDaoException wde) { dataLogger.error("Error recording ISB payload: " + wde.getMessage()); } } } catch (DataAccessException de) { dataLogger.error("Error creating ISB message: " + de.getMessage()); } } return isbMessageId; }
From source file:com.sfs.whichdoctor.dao.TagDAOImpl.java
/** * Creates the tag bean./* ww w . j a v a 2 s . co m*/ * * @param tag the tag * @param checkUser the check user * @param privileges the privileges * @return the int * @throws WhichDoctorDaoException the which doctor dao exception */ public final int create(final TagBean tag, final UserBean checkUser, final PrivilegesBean privileges) throws WhichDoctorDaoException { if (tag.getGUID() == 0) { throw new WhichDoctorDaoException("Tag must have a GUID > 0"); } if (StringUtils.isBlank(tag.getTagName())) { throw new WhichDoctorDaoException("Tag cannot be an empty string"); } if (StringUtils.isBlank(tag.getSecurity())) { throw new WhichDoctorDaoException("A security level must be set for the tag"); } if (!this.uniqueTest(tag)) { /* The tag submitted is not unique */ throw new WhichDoctorDaoException("Sorry a tag of these " + "characteristics already exists"); } boolean allowCreate = privileges.getPrivilege(checkUser, tag.getSecurity(), "modify"); /* If the tag is of type private default to allow */ if (StringUtils.equalsIgnoreCase(tag.getTagType(), "Private")) { allowCreate = true; } if (!allowCreate) { throw new WhichDoctorDaoException("Sorry, you do not have the required privileges to create this tag"); } int objectTypeId = 0; try { ObjectTypeBean object = this.getObjectTypeDAO().load("Tag Type", "", tag.getTagType()); objectTypeId = object.getObjectTypeId(); } catch (Exception e) { dataLogger.error("Error identifying object type for tag: " + e.getMessage()); throw new WhichDoctorDaoException("Error identifying object type for tag"); } int tagId = 0; Timestamp sqlTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis()); int updateCount = 0; try { updateCount = this.getJdbcTemplateWriter().update(this.getSQL().getValue("tag/create"), new Object[] { tag.getGUID(), objectTypeId, DataFilter.capitaliseFirst(tag.getTagName()), sqlTimeStamp, checkUser.getDN() }); } catch (DataAccessException de) { dataLogger.error("Error creating tag: " + de.getMessage()); throw new WhichDoctorDaoException("Error creating tag: " + de.getMessage()); } if (updateCount > 0) { dataLogger.info(checkUser.getDN() + " successfully created tag"); final String findMaxSQL = getSQL().getValue("tag/findMax"); tagId = this.getJdbcTemplateWriter().queryForInt(findMaxSQL); } return tagId; }
From source file:com.sfs.whichdoctor.dao.TagDAOImpl.java
/** * Modify the tag bean./*www . java 2 s . c o m*/ * * @param tag the tag * @param checkUser the check user * @param privileges the privileges * @return the int * @throws WhichDoctorDaoException the which doctor dao exception */ public final int modify(final TagBean tag, final UserBean checkUser, final PrivilegesBean privileges) throws WhichDoctorDaoException { if (tag.getId() == 0) { throw new WhichDoctorDaoException("Tag must have a valid id"); } if (tag.getGUID() == 0) { throw new WhichDoctorDaoException("Tag must have a GUID > 0"); } if (StringUtils.isBlank(tag.getTagName())) { throw new WhichDoctorDaoException("Tag cannot be an empty string"); } if (!this.uniqueTest(tag)) { /* The tag submitted is not unique */ throw new WhichDoctorDaoException("Sorry a tag of these " + "characteristics already exists"); } int objectTypeId = 0; try { ObjectTypeBean object = this.getObjectTypeDAO().load("Tag Type", "", tag.getTagType()); objectTypeId = object.getObjectTypeId(); } catch (Exception e) { dataLogger.error("Error identifying object type for tag: " + e.getMessage()); throw new WhichDoctorDaoException("Error identifying object type for tag"); } boolean allowModify = privileges.getPrivilege(checkUser, tag.getSecurity(), "modify"); /* If the tag is of type private default to allow */ if (StringUtils.equalsIgnoreCase(tag.getTagType(), "Private")) { allowModify = true; } if (!allowModify) { throw new WhichDoctorDaoException("Sorry, you do not have the required privileges to modify this tag"); } int tagId = 0; dataLogger.info(checkUser.getDN() + " attempting to modify tag"); try { final Timestamp sqlTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis()); final int updateCount = this.getJdbcTemplateWriter().update(this.getSQL().getValue("tag/modify"), new Object[] { tag.getGUID(), objectTypeId, DataFilter.capitaliseFirst(tag.getTagName()), sqlTimeStamp, checkUser.getDN(), tag.getId() }); if (updateCount > 0) { dataLogger.info(checkUser.getDN() + " successfully modified tag"); tagId = tag.getId(); } else { dataLogger.error(checkUser.getUserName() + ": could not modify tag"); throw new WhichDoctorDaoException("Failed to modify tag entry"); } } catch (DataAccessException de) { dataLogger.error("Error modifying tag: " + de.getMessage()); throw new WhichDoctorDaoException("Error modifying tag: " + de.getMessage()); } return tagId; }
From source file:pe.gob.mef.gescon.hibernate.impl.ConsultaDaoImpl.java
/** * * @param filters/* w ww.ja va2s .c o m*/ * @return */ @Override public List<HashMap> getDestacadosByTipoConocimiento(HashMap filters) { String ntipoconocimientoid = ((BigDecimal) filters.get("ntipoconocimientoid")).toString(); final StringBuilder sql = new StringBuilder(); Object object = null; try { if (StringUtils.isNotBlank(ntipoconocimientoid) && ntipoconocimientoid.equals("1")) { sql.append("SELECT "); sql.append(" a.nbaselegalid AS ID, a.vnumero AS NOMBRE, a.vnombre AS SUMILLA, "); sql.append( " a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, "); sql.append( " 1 AS IDTIPOCONOCIMIENTO, 'Base Legal' AS TIPOCONOCIMIENTO, a.nestadoid AS IDESTADO, c.vnombre AS ESTADO "); sql.append("FROM TBASELEGAL a "); sql.append(" INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid "); sql.append(" INNER JOIN MTESTADO_BASELEGAL c ON a.nestadoid = c.nestadoid "); sql.append("WHERE a.nactivo = :ACTIVO "); sql.append("AND a.ndestacado = :DESTACADO "); sql.append("AND a.nestadoid IN (3,5,6) "); // Publicada, Concordada y Modificada. } if (StringUtils.isNotBlank(ntipoconocimientoid) && ntipoconocimientoid.equals("2")) { sql.append("SELECT "); sql.append(" a.npreguntaid AS ID, a.vasunto AS NOMBRE, a.vrespuesta AS SUMILLA, "); sql.append( " a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, "); sql.append(" 2 AS IDTIPOCONOCIMIENTO, 'Preguntas y Respuestas' AS TIPOCONOCIMIENTO, "); sql.append(" a.nsituacionid AS IDESTADO, c.vnombre AS ESTADO "); sql.append("FROM TPREGUNTA a "); sql.append(" INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid "); sql.append(" INNER JOIN MTSITUACION c ON a.nsituacionid = c.nsituacionid "); sql.append("WHERE a.nactivo = :ACTIVO "); sql.append("AND a.ndestacado = :DESTACADO "); sql.append("AND a.nsituacionid = 6 "); // Publicada } if (StringUtils.isNotBlank(ntipoconocimientoid) && (ntipoconocimientoid.equals("3") || ntipoconocimientoid.equals("4") || ntipoconocimientoid.equals("5") || ntipoconocimientoid.equals("6"))) { sql.append("SELECT "); sql.append(" a.nconocimientoid AS ID, a.vtitulo AS NOMBRE, a.vdescripcion AS SUMILLA, "); sql.append( " a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, "); sql.append(" a.ntpoconocimientoid AS IDTIPOCONOCIMIENTO, d.vnombre AS TIPOCONOCIMIENTO, "); sql.append(" a.nsituacionid AS IDESTADO, c.vnombre AS ESTADO "); sql.append("FROM TCONOCIMIENTO a "); sql.append(" INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid "); sql.append(" INNER JOIN MTSITUACION c ON a.nsituacionid = c.nsituacionid "); sql.append(" INNER JOIN MTTIPO_CONOCIMIENTO d ON a.ntpoconocimientoid = d.ntpoconocimientoid "); sql.append("WHERE a.nactivo = :ACTIVO "); sql.append("AND a.ndestacado = :DESTACADO "); sql.append("AND a.nsituacionid = 6 AND a.NTPOCONOCIMIENTOID= ").append(ntipoconocimientoid) .append(" "); // Publicado } sql.append("ORDER BY 5, 7 DESC "); object = getHibernateTemplate().execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { Query query = session.createSQLQuery(sql.toString()); query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); query.setParameter("ACTIVO", BigDecimal.ONE); query.setParameter("DESTACADO", BigDecimal.ONE); return query.list(); } }); } catch (DataAccessException e) { e.getMessage(); e.printStackTrace(); } return (List<HashMap>) object; }
From source file:org.opennms.ng.dao.support.DistributedStatusResourceType.java
/** * <p>getResourcesForLocationMonitor</p> * * @param locationMonitorId a int./*from w ww .j av a 2 s .c o m*/ * @return a {@link java.util.List} object. */ public List<OnmsResource> getResourcesForLocationMonitor(int locationMonitorId) { ArrayList<OnmsResource> resources = new ArrayList<OnmsResource>(); /* * Verify that the node directory exists so we can throw a good * error message if not. */ File locationMonitorDirectory; try { locationMonitorDirectory = getLocationMonitorDirectory(locationMonitorId, true); } catch (DataAccessException e) { throw new ObjectRetrievalFailureException("The '" + getName() + "' resource type does not exist on this location Monitor. Nested exception is: " + e.getClass().getName() + ": " + e.getMessage(), e); } File[] intfDirs = locationMonitorDirectory.listFiles(RrdFileConstants.INTERFACE_DIRECTORY_FILTER); // XXX is this test even needed? if (intfDirs == null) { return resources; } // XXX this isn't right at all for (File intfDir : intfDirs) { String d = intfDir.getName(); String defName = getDefinitionNameFromLocationMonitorDirectory(d); int id = getLocationMonitorIdFromLocationMonitorDirectory(d); resources.add(createResource(defName, id, intfDir.getName())); } return resources; }
From source file:konditer.client.dao.ContactDao.java
@Override public int updateContact(int contactId, int newContactTypeId, int newCustomerId, String newContactData) { System.out.println(" ContactDao.updateContact c : " + "contactId: " + contactId + " | newContactTypeId: " + newContactTypeId + " | newCustomerId: " + newCustomerId + " | newContactData=" + newContactData); String SQL_QUERY = "UPDATE contacts " + "SET CONTACT_TYPE_ID = ?, " + "CUSTOMER_ID = ?, " + "CONTACT_DATA = ? " + "WHERE CONTACT_ID = ?"; int rowCount = 0; try {// w w w . j av a2s .c o m rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { newContactTypeId, newCustomerId, newContactData, contactId }, new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER }); Logger.getLogger(ContactDao.class.getName()).log(Level.SEVERE, " . ?: {0} .", rowCount + "\n" + contactDao.getContact(contactId).toString()); } catch (DataAccessException e) { rowCount = 0; Logger.getLogger(ContactDao.class.getName()).log(Level.SEVERE, " . ?: {0} .", rowCount + ";\nDataAccessException.message:{" + e.getMessage() + "}"); } return rowCount; }
From source file:org.itracker.services.authentication.DefaultAuthenticator.java
/** * Checks the login of a user against the user profile provided in ITracker. This is * the default authentication scheme provided by ITracker. * * @param login the login the user/client provided * @param authentication the user's authentication information, if known * @param authType the type of authentication information being provided * @param reqSource the source of the request (eg web, api) * @return a User if the login is successful * @throws AuthenticatorException an exception if the login is unsuccessful, or an error occurs *//*from ww w.j a v a2s . c om*/ public User checkLogin(final String login, final Object authentication, final int authType, final int reqSource) throws AuthenticatorException { if (logger.isDebugEnabled()) { logger.debug("Checking login for " + login + " using DefaultAuthenticator"); } if (login != null && authentication != null && !login.equals("")) { User user; try { user = getUserService().getUserByLogin(login); } catch (DataAccessException e) { logger.error("checkLogin: failed to get user by login: " + login, e); throw new AuthenticatorException(AuthenticatorException.UNKNOWN_USER, e.getMessage()); } if (user.getStatus() != UserUtilities.STATUS_ACTIVE) { AuthenticatorException e = new AuthenticatorException(AuthenticatorException.INACTIVE_ACCOUNT); logger.info("checkLogin: user is inactive, user: " + user, e); throw e; } String userPassword; try { userPassword = getUserService().getUserPasswordByLogin(login); } catch (DataAccessException e) { AuthenticatorException ex = new AuthenticatorException(e.getMessage(), authType); logger.info("checkLogin: user is inactive, user: " + user, ex); throw e; } if (userPassword == null || userPassword.equals("")) { AuthenticatorException e = new AuthenticatorException(AuthenticatorException.INVALID_PASSWORD); logger.info("checkLogin: user has no password, user: " + user, e); throw e; } try { if (!userPassword.endsWith("=")) { logger.info("checkLogin: User " + login + " has old style password. Converting to SHA1 hash."); try { user.setPassword(UserUtilities.encryptPassword(userPassword)); getUserService().updateUser(user); } catch (UserException ue) { logger.error("checkLogin: User password conversion failed for user " + user, ue); throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR); } } if (authType == AUTH_TYPE_PASSWORD_PLAIN) { if (!userPassword.equals(UserUtilities.encryptPassword((String) authentication))) { throw new AuthenticatorException(AuthenticatorException.INVALID_PASSWORD); } } else if (authType == AUTH_TYPE_PASSWORD_ENC) { if (!userPassword.equals(authentication)) { throw new AuthenticatorException(AuthenticatorException.INVALID_PASSWORD); } } else { logger.info("checkLogin: invalid authenticator type: " + authType); throw new AuthenticatorException(AuthenticatorException.INVALID_AUTHENTICATION_TYPE); } } catch (ClassCastException cce) { logger.error("checkLogin: Authenticator was of wrong type.", cce); throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR); } catch (PasswordException pe) { throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR); } catch (AuthenticatorException ae) { if (logger.isDebugEnabled()) { logger.debug("checkLogin: failed to authenticate " + login, ae); } throw ae; } return user; } logger.info( "checkLogin: no login was supplied: " + login + ", type: " + authType + ", source: " + reqSource); throw new AuthenticatorException(AuthenticatorException.INVALID_DATA); }
From source file:com.gvmax.web.api.WebAppAPI.java
@RequestMapping(value = "/enableGV", method = RequestMethod.POST) @Timed/* w w w .j a v a 2 s.com*/ @ExceptionMetered public ModelMap enableGV(@RequestParam(value = "password") String password, @RequestParam(value = "pin", required = false) String pin, HttpSession session, HttpServletResponse resp) { try { User user = getUser(service, session, pin); if (user == null) { invalidCredentials(resp); return null; } service.changePassword(user.getEmail(), password, true); return new ModelMap("result", "ok"); } catch (DataAccessException e) { internalError(e, resp); return null; } catch (IOException e) { sendError(400, e.getMessage(), resp); return null; } }
From source file:pe.gob.mef.gescon.hibernate.impl.ConsultaDaoImpl.java
@Override public List<HashMap> getQueryFilter(HashMap filters) { final String fCategoria = (String) filters.get("fCategoria"); final Date fFromDate = (Date) filters.get("fFromDate"); final Date fToDate = (Date) filters.get("fToDate"); final String fType = (String) filters.get("fType"); final String fCodesBL = (String) filters.get("fCodesBL"); final String fCodesPR = (String) filters.get("fCodesPR"); final String fCodesC = (String) filters.get("fCodesC"); final String fText = (String) filters.get("fText"); final String order = (String) filters.get("order"); SimpleDateFormat sdf = new SimpleDateFormat(Constante.FORMAT_DATE_SHORT); final StringBuilder sql = new StringBuilder(); Object object = null;// ww w .j ava2 s . c om try { sql.append("SELECT x.ID, x.NOMBRE, x.SUMILLA, x.IDCATEGORIA, x.CATEGORIA, x.FECHA, "); sql.append(" x.IDTIPOCONOCIMIENTO, x.TIPOCONOCIMIENTO, x.IDESTADO, x.ESTADO, x.FLG, "); sql.append(" x.SUMA, x.CONTADOR, DECODE(x.CONTADOR,0,0,x.SUMA/x.CONTADOR) AS PROMEDIO "); sql.append("FROM (SELECT "); sql.append(" a.nbaselegalid AS ID, a.vnumero AS NOMBRE, a.vnombre AS SUMILLA, "); sql.append( " a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, "); sql.append( " 1 AS IDTIPOCONOCIMIENTO, 'Base Legal' AS TIPOCONOCIMIENTO, a.nestadoid AS IDESTADO, c.vnombre AS ESTADO, "); sql.append( " 0 AS FLG, NVL(SUM(e.ncalificacion),0) AS SUMA, NVL(COUNT(e.ncalificacion),0) AS CONTADOR "); sql.append(" FROM TBASELEGAL a "); sql.append(" INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid "); sql.append(" INNER JOIN MTESTADO_BASELEGAL c ON a.nestadoid = c.nestadoid "); sql.append(" LEFT OUTER JOIN TCALIFICACION_BASELEGAL e ON a.nbaselegalid = e.nbaselegalid "); sql.append(" WHERE a.nactivo = :ACTIVO "); sql.append(" AND c.nestadoid IN (3,4,5,6) AND b.NESTADO = 1 "); if (StringUtils.isNotBlank(fCategoria)) { sql.append(" AND a.ncategoriaid IN (").append(fCategoria).append(") "); } if (fFromDate != null) { sql.append(" AND TRUNC(a.dfechapublicacion) >= TO_DATE('").append(sdf.format(fFromDate)) .append("','dd/mm/yyyy') "); } if (fToDate != null) { sql.append(" AND TRUNC(a.dfechapublicacion) <= TO_DATE('").append(sdf.format(fToDate)) .append("','dd/mm/yyyy') "); } if (StringUtils.isNotBlank(fCodesBL)) { sql.append(" AND a.nbaselegalid IN (").append(fCodesBL).append(") "); } if (StringUtils.isNotBlank(fText)) { sql.append(" AND a.vnumero LIKE '%").append(fText).append("%' "); } sql.append(" GROUP BY a.nbaselegalid, a.vnumero, a.vnombre, a.ncategoriaid, b.vnombre, "); sql.append(" a.dfechapublicacion, 1, 'Base Legal', a.nestadoid, c.vnombre, 0 "); sql.append(" ) x "); sql.append("WHERE 1 IN (").append(fType).append(") "); //BASE LEGAL sql.append("UNION "); sql.append("SELECT y.ID, y.NOMBRE, y.SUMILLA, y.IDCATEGORIA, y.CATEGORIA, y.FECHA, "); sql.append(" y.IDTIPOCONOCIMIENTO, y.TIPOCONOCIMIENTO, y.IDESTADO, y.ESTADO, y.FLG, "); sql.append(" y.SUMA, y.CONTADOR, DECODE(y.CONTADOR,0,0,y.SUMA/y.CONTADOR) AS PROMEDIO "); sql.append("FROM (SELECT "); sql.append( " a.npreguntaid AS ID, a.vasunto AS NOMBRE, a.vdetalle AS SUMILLA, a.ncategoriaid AS IDCATEGORIA, "); sql.append( " b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, 2 AS IDTIPOCONOCIMIENTO, "); sql.append( " 'Preguntas y Respuestas' AS TIPOCONOCIMIENTO, a.nsituacionid AS IDESTADO, c.vnombre AS ESTADO, "); sql.append( " 0 AS FLG, NVL(SUM(e.ncalificacion),0) AS SUMA, NVL(COUNT(e.ncalificacion),0) AS CONTADOR "); sql.append(" FROM TPREGUNTA a "); sql.append(" INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid "); sql.append(" INNER JOIN MTSITUACION c ON a.nsituacionid = c.nsituacionid "); sql.append(" LEFT OUTER JOIN TCALIFICACION_PREGUNTA e ON a.npreguntaid = e.npreguntaid "); sql.append(" WHERE a.nactivo = :ACTIVO "); sql.append(" AND c.nsituacionid = 6 AND b.NESTADO = 1 "); if (StringUtils.isNotBlank(fCategoria)) { sql.append(" AND a.ncategoriaid IN (").append(fCategoria).append(") "); } if (fFromDate != null) { sql.append(" AND TRUNC(a.dfechacreacion) >= TO_DATE('").append(sdf.format(fFromDate)) .append("','dd/mm/yyyy') "); } if (fToDate != null) { sql.append(" AND TRUNC(a.dfechacreacion) <= TO_DATE('").append(sdf.format(fToDate)) .append("','dd/mm/yyyy') "); } if (StringUtils.isNotBlank(fCodesPR)) { sql.append(" AND a.npreguntaid IN (").append(fCodesPR).append(") "); } if (StringUtils.isNotBlank(fText)) { sql.append(" AND a.vasunto LIKE '%").append(fText).append("%' "); } sql.append(" GROUP BY a.npreguntaid, a.vasunto, a.vdetalle, a.ncategoriaid, b.vnombre, "); sql.append(" a.dfechapublicacion, 2, 'Preguntas y Respuestas', a.nsituacionid, c.vnombre, 0 "); sql.append(" ) y "); sql.append("WHERE 2 IN (").append(fType).append(") "); //PREGUNTAS Y RESPUESTAS sql.append("UNION "); sql.append("SELECT z.ID, z.NOMBRE, z.SUMILLA, z.IDCATEGORIA, z.CATEGORIA, z.FECHA, "); sql.append(" z.IDTIPOCONOCIMIENTO, z.TIPOCONOCIMIENTO, z.IDESTADO, z.ESTADO, z.FLG, "); sql.append(" z.SUMA, z.CONTADOR, DECODE(z.CONTADOR,0,0,z.SUMA/z.CONTADOR) AS PROMEDIO "); sql.append("FROM (SELECT "); sql.append(" a.nconocimientoid AS ID, a.vtitulo AS NOMBRE, a.vdescripcion AS SUMILLA, "); sql.append( " a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, "); sql.append(" a.ntpoconocimientoid AS IDTIPOCONOCIMIENTO, d.vnombre AS TIPOCONOCIMIENTO, "); sql.append(" a.nsituacionid AS IDESTADO, c.vnombre AS ESTADO, a.nflgvinculo AS FLG, "); sql.append( " NVL(SUM(e.ncalificacion),0) AS SUMA, NVL(COUNT(e.ncalificacion),0) AS CONTADOR "); sql.append(" FROM TCONOCIMIENTO a "); sql.append(" INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid "); sql.append(" INNER JOIN MTSITUACION c ON a.nsituacionid = c.nsituacionid "); sql.append(" INNER JOIN MTTIPO_CONOCIMIENTO d ON a.ntpoconocimientoid = d.ntpoconocimientoid "); sql.append(" AND a.ntpoconocimientoid IN (").append(fType).append(") "); sql.append(" LEFT OUTER JOIN TCALIFICACION e ON a.nconocimientoid = e.nconocimientoid "); sql.append(" WHERE a.nactivo = :ACTIVO "); sql.append(" AND c.nsituacionid = 6 AND b.nestado = 1 "); if (StringUtils.isNotBlank(fCategoria)) { sql.append(" AND a.ncategoriaid IN (").append(fCategoria).append(") "); } if (fFromDate != null) { sql.append(" AND TRUNC(a.dfechacreacion) >= TO_DATE('").append(sdf.format(fFromDate)) .append("','dd/mm/yyyy') "); } if (fToDate != null) { sql.append(" AND TRUNC(a.dfechacreacion) <= TO_DATE('").append(sdf.format(fToDate)) .append("','dd/mm/yyyy') "); } if (StringUtils.isNotBlank(fCodesC)) { sql.append(" AND a.nconocimientoid IN (").append(fCodesC).append(") "); } if (StringUtils.isNotBlank(fText)) { sql.append(" AND a.vtitulo LIKE '%").append(fText).append("%' "); } sql.append( " GROUP BY a.nconocimientoid, a.vtitulo, a.vdescripcion, a.ncategoriaid, b.vnombre, "); sql.append( " a.dfechapublicacion, a.ntpoconocimientoid, d.vnombre, a.nsituacionid, c.vnombre, a.nflgvinculo "); sql.append(" ) z "); sql.append("WHERE (3 IN (").append(fType).append(") OR 4 IN (").append(fType).append(") OR 5 IN (") .append(fType).append(") OR 6 IN (").append(fType).append(")) "); //WIKI if (StringUtils.isNotBlank(order)) { sql.append("ORDER BY ").append(order); } else { sql.append("ORDER BY 6 DESC "); } object = getHibernateTemplate().execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { Query query = session.createSQLQuery(sql.toString()); query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); if (StringUtils.isNotBlank(sql.toString())) { query.setParameter("ACTIVO", BigDecimal.ONE); } return query.list(); } }); } catch (DataAccessException e) { e.getMessage(); e.printStackTrace(); } return (List<HashMap>) object; }