List of usage examples for org.apache.commons.lang3 StringUtils replace
public static String replace(final String text, final String searchString, final String replacement)
Replaces all occurrences of a String within another String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("any", null, *) = "any" StringUtils.replace("any", *, null) = "any" StringUtils.replace("any", "", *) = "any" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "b" StringUtils.replace("aba", "a", "z") = "zbz"
From source file:com.neophob.sematrix.listener.TcpServer.java
/** * tcp server thread.//from www. j a va 2s. c o m */ public void run() { LOG.log(Level.INFO, "Ready receiving messages..."); while (Thread.currentThread() == runner) { if (tcpServer != null) { try { //check if client is available if (client != null && client.active()) { //do not send sound status to gui - very cpu intensive! //sendSoundStatus(); if ((count % 20) == 2 && Collector.getInstance().isRandomMode()) { sendStatusToGui(); } } Client c = tcpServer.available(); if (c != null && c.available() > 0) { //clean message String msg = lastMsg + StringUtils.replace(c.readString(), "\n", ""); //add replacement end string msg = StringUtils.replace(msg, FUDI_ALTERNATIVE_END_MARKER, FUDI_MSG_END_MARKER); msg = StringUtils.trim(msg); int msgCount = StringUtils.countMatches(msg, FUDI_MSG_END_MARKER); LOG.log(Level.INFO, "Got Message: {0} cnt: {1}", new Object[] { msg, msgCount }); //work around bug - the puredata gui sends back a message as soon we send one long delta = System.currentTimeMillis() - lastMessageSentTimestamp; if (delta < FLOODING_TIME) { LOG.log(Level.INFO, "Ignore message, flooding protection ({0}<{1})", new String[] { "" + delta, "" + FLOODING_TIME }); //delete message msgCount = 0; msg = ""; } //ideal, one message receieved if (msgCount == 1) { msg = StringUtils.removeEnd(msg, FUDI_MSG_END_MARKER); lastMsg = ""; processMessage(StringUtils.split(msg, ' ')); } else if (msgCount == 0) { //missing end of message... save it lastMsg = msg; } else { //more than one message receieved, split it //TODO: reuse partial messages lastMsg = ""; String[] msgs = msg.split(FUDI_MSG_END_MARKER); for (String s : msgs) { s = StringUtils.trim(s); s = StringUtils.removeEnd(s, FUDI_MSG_END_MARKER); processMessage(StringUtils.split(s, ' ')); } } } } catch (Exception e) { } } count++; try { Thread.sleep(50); } catch (InterruptedException e) { //Ignored } } }
From source file:net.pms.network.UPNPHelper.java
/** * Send reply.//from w ww .j av a 2 s . c om * * @param host the host * @param port the port * @param msg the msg * @throws IOException Signals that an I/O exception has occurred. */ private static void sendReply(String host, int port, String msg) { DatagramSocket datagramSocket = null; try { datagramSocket = new DatagramSocket(); InetAddress inetAddr = InetAddress.getByName(host); DatagramPacket dgmPacket = new DatagramPacket(msg.getBytes(), msg.length(), inetAddr, port); logger.trace( "Sending this reply [" + host + ":" + port + "]: " + StringUtils.replace(msg, CRLF, "<CRLF>")); datagramSocket.send(dgmPacket); } catch (Exception e) { logger.info(e.getMessage()); logger.debug("Error sending reply", e); } finally { if (datagramSocket != null) { datagramSocket.close(); } } }
From source file:com.dominion.salud.mpr.ws.rest.MPRMessagesRESTHandlerService.java
@ResponseBody @RequestMapping(value = "/receiveMessages", method = RequestMethod.POST, produces = "application/json") public ResponseEntity<String> receiveMessages(@RequestBody(required = true) String message) { logger.info("RECIBIENDO MENSAJE ENTRANTE"); logger.info(message);//ww w . jav a 2 s .c o m ACK ack = null; AbstractParser parser = null; Message hl7message = null; String cod_centro = ""; try { message = StringUtils.replace(message, "\n", "\r"); if (StringUtils.isBlank(message)) { //Validaciones previas throw new HL7Exception("No se ha indicado un mensaje entrante: [" + message + "]"); } //Deternima el formato del mensaje logger.debug(" Determinando el formato del mensaje y el parseador a emplear"); if (EncodingDetector.isEr7Encoded(message)) { parser = new ER7Parser(); logger.debug(" Formato del mensaje ER7 y parseador [" + parser.getClass() + "] aceptados"); } else { throw new HL7Exception("Formato de mensaje no reconocido. El formato soportado es ER7"); } logger.debug(" Formato del mensaje y parseador determinados correctamente"); //Parseado del mensaje logger.debug(" Parseando mensaje [" + parser.getClass() + "]"); hl7message = parser.parse(message); logger.debug(" Mensaje parseado correctamente [" + hl7message.getClass() + "]"); //Validaciones del MPR logger.debug(" Validando el mensaje"); MSH msh = (MSH) hl7message.get("MSH"); if (StringUtils.isBlank(msh.getMessageControlID().getValue())) { //MSH.10 throw new HL7Exception( "No se ha indicado el identificador de mensaje (MSH-10: Message Control ID)"); } if (hl7message.getClass() == ZDS_O13.class) { //DISPENSACIONES ZDS_O13 zds_o13 = (ZDS_O13) hl7message; PID pid = zds_o13.getPATIENT().getPID(); PV1 pv1 = zds_o13.getPATIENT().getPATIENT_VISIT().getPV1(); Integer nhc = null; String cipa = null; for (int i = 0; i < pid.getPatientIdentifierList().length; i++) { // PID.3 - PatientIdentifierList if (StringUtils.equalsIgnoreCase( pid.getPatientIdentifierList(i).getIdentifierTypeCode().getValue(), "PI")) { if (StringUtils.isNotBlank(pid.getPatientIdentifierList(i).getIDNumber().getValue())) { try { nhc = NumberUtils .createInteger(pid.getPatientIdentifierList(i).getIDNumber().getValue()); } catch (Exception e) { logger.warn("El NHC no es correcto (PID-3.1: Patient Identifier List [PI])"); } } } else if (StringUtils.equalsIgnoreCase( pid.getPatientIdentifierList(i).getIdentifierTypeCode().getValue(), "CIPA")) { if (StringUtils.isNotBlank(pid.getPatientIdentifierList(i).getIDNumber().getValue())) { cipa = pid.getPatientIdentifierList(i).getIDNumber().getValue(); } else { logger.warn("El CIPA no es correcto (PID-3.1: Patient Identifier List [CIPA])"); } } } if (nhc == null && StringUtils.isBlank(cipa)) { throw new HL7Exception( "No se ha indicado el NHC (PID-3.1: Patient Identifier List [PI]) ni el CIPA (PID-3.1: Patient Identifier List [CIPA])"); } //PV1.2 - Clase de Paciente if (StringUtils.isNotBlank(pv1.getPatientClass().getValue())) { //PV1.2 - Clase de Paciente if (StringUtils.equals(pv1.getPatientClass().getValue(), "O")) { //Outpatient if (StringUtils.isBlank(pv1.getPatientType().getValue())) { //PV1.18 - Tipo de Paciente throw new HL7Exception("No se ha indicado el tipo de paciente (PV1-18: Patient Type)"); } } } else { throw new HL7Exception("No se ha indicado la clase de paciente (PV1-2: Patient Class)"); } //PV1.19.1 - Codigo de Episodio if (StringUtils.isBlank(pv1.getVisitNumber().getIDNumber().getValue())) { throw new HL7Exception("No se ha indicado el episodio del paciente (PV1.19: Visit Number)"); } List<ZDS_O13_ORDER> zds_o13_orders = zds_o13.getORDERAll(); for (ZDS_O13_ORDER zds_o13_order : zds_o13_orders) { ORC orc = zds_o13_order.getORC(); TQ1 tq1 = zds_o13_order.getTIMING().getTQ1(); RXD rxd = zds_o13_order.getRXD(); Z01 z01 = zds_o13_order.getZ01(); //ORC.21.10 - OrganizationIdentifier if (StringUtils .isBlank(orc.getOrderingFacilityName(0).getOrganizationIdentifier().getValue())) { //ORC.21.10 throw new HL7Exception( "No se ha indicado el centro de origen (ORC-21.10: OrganizationIdentifier)"); } else { cod_centro = orc.getOrderingFacilityName(0).getOrganizationIdentifier().getValue(); } //ORC.2.1 - Codigo de Prescripcion if (StringUtils.isBlank(orc.getPlacerOrderNumber().getEntityIdentifier().getValue())) { throw new HL7Exception( "No se ha indicado el identificador de la prescripcion (ORC-2.1: Placer Order Number)"); } //ORC.3.1 - Codigo de Dispensacion if (StringUtils.isBlank(orc.getFillerOrderNumber().getEntityIdentifier().getValue())) { throw new HL7Exception( "No se ha indicado el identificador de la dispensacion (ORC-3.1: Filler Order Number)"); } //ORC.10 - Medico Prescriptor if (StringUtils.isBlank(orc.getEnteredBy(0).getIDNumber().getValue())) { //ORC.10.1 throw new HL7Exception( "No se ha indicado el codigo del medico prescriptor (ORC-10.1: Entered By)"); } if (StringUtils.isBlank(orc.getEnteredBy(0).getGivenName().getValue())) { //ORC.10.3 throw new HL7Exception( "No se ha indicado el nombre del medico prescriptor (ORC-10.3: Entered By)"); } if (StringUtils.isBlank(orc.getEnteredBy(0).getFamilyName().getSurname().getValue())) { //ORC.10.2.1 throw new HL7Exception( "No se ha indicado el apellido del medico prescriptor (ORC-10.2.1: Entered By)"); } //RXD.2.1 - DispenseGiveCode (Codigo Nacional de la Marca) if (StringUtils.isBlank(rxd.getDispenseGiveCode().getIdentifier().getValue())) { //RXD.2.1 throw new HL7Exception( "No se ha indicado el codigo nacional de la marca (RXD-2.1: DispenseGiveCode)"); } //RXD.2.2 - DispenseGiveCode (Descripcion de la Marca) if (StringUtils.isBlank(rxd.getDispenseGiveCode().getText().getValue())) { //RXD.2.2 throw new HL7Exception( "No se ha indicado la descripcion de la marca (RXD-2.2: DispenseGiveCode)"); } //RXD.3 - Fecha de la Dispensacion if (StringUtils.isBlank(rxd.getDateTimeDispensed().getTime().getValue())) { throw new HL7Exception( "No se ha indicado la fecha de la dispensacion (RXD-3: Date/Time Dispensed)"); } //RXD.4 - ActualDispenseAmount (Unidades Dispensadas en Forma Farmaceutica) if (StringUtils.isNotBlank(rxd.getActualDispenseAmount().getValue())) { //RXD.4 try { NumberUtils.createDouble(rxd.getActualDispenseAmount().getValue()); } catch (Exception e) { throw new HL7Exception("Las unidades dispensadas no son correctas [" + rxd.getActualDispenseAmount().getValue() + "] (RXD-4: ActualDispenseAmount)"); } } else { throw new HL7Exception( "No se han indicado las unidades dispensadas (RXD-4: ActualDispenseAmount)"); } //TQ1.7 - Fecha de Inicio de la Prescripcion if (StringUtils.isBlank(tq1.getStartDateTime().getTime().getValue())) { throw new HL7Exception( "No se ha indicado la fecha de inicio de la prescripcion (TQ1-7: Start Date/Time)"); } //Z01.9 - Dosis Prescrita en Unidad de Medida if (StringUtils.isNotBlank(z01.getDosisPrescrita().getValue())) { //Z01.9 try { NumberUtils.createDouble(z01.getDosisPrescrita().getValue()); } catch (Exception e) { throw new HL7Exception( "La dosis prescrita no es correcta [" + z01.getDosisPrescrita().getValue() + "] (Z01-9: Dosis Prescrita en Unidad de Medida)"); } } else { throw new HL7Exception( "No se ha indicado dosis prescrita (Z01-9: Dosis Prescrita en Unidad de Medida)"); } } } else if (hl7message.getClass() == ZMP_O09.class) { //PRESCRIPCIONES (razon fin) ZMP_O09 zmp_o09 = (ZMP_O09) hl7message; PID pid = zmp_o09.getPATIENT().getPID(); PV1 pv1 = zmp_o09.getPATIENT().getPATIENT_VISIT().getPV1(); //PID.3 - Identificadores del paciente (NHC) y (CIPA) Integer nhc = null; String cipa = null; for (int i = 0; i < pid.getPatientIdentifierList().length; i++) { // PID.3 - PatientIdentifierList if (StringUtils.equalsIgnoreCase( pid.getPatientIdentifierList(i).getIdentifierTypeCode().getValue(), "PI")) { if (StringUtils.isNotBlank(pid.getPatientIdentifierList(i).getIDNumber().getValue())) { try { nhc = NumberUtils .createInteger(pid.getPatientIdentifierList(i).getIDNumber().getValue()); } catch (Exception e) { throw new HL7Exception("El NHC no es correcto (PID-3.1: Patient Identifier List)"); } } else { throw new HL7Exception("No se ha indicado el NHC (PID-3.1: Patient Identifier List)"); } } else if (StringUtils.equalsIgnoreCase( pid.getPatientIdentifierList(i).getIdentifierTypeCode().getValue(), "CIPA")) { if (StringUtils.isBlank(pid.getPatientIdentifierList(i).getIDNumber().getValue())) { throw new HL7Exception("El CIPA no es correcto (PID-3.1: Patient Identifier List)"); } else { cipa = pid.getPatientIdentifierList(i).getIDNumber().getValue(); } } } if (nhc == null) { throw new HL7Exception("No se ha indicado el NHC (PID-3.1: Patient Identifier List)"); } if (StringUtils.isBlank(cipa)) { throw new HL7Exception("No se ha indicado el CIPA (PID-3.1: Patient Identifier List)"); } //PV1.2 - Clase de Paciente if (StringUtils.isNotBlank(pv1.getPatientClass().getValue())) { //PV1.2 - Clase de Paciente if (StringUtils.equals(pv1.getPatientClass().getValue(), "O")) { //Outpatient if (StringUtils.isBlank(pv1.getPatientType().getValue())) { //PV1.18 - Tipo de Paciente throw new HL7Exception("No se ha indicado el tipo de paciente (PV1-18: Patient Type)"); } } } else { throw new HL7Exception("No se ha indicado la clase de paciente (PV1-2: Patient Class)"); } //PV1.19.1 - Codigo de Episodio if (StringUtils.isBlank(pv1.getVisitNumber().getIDNumber().getValue())) { throw new HL7Exception("No se ha indicado el episodio del paciente (PV1.19: Visit Number)"); } List<ZMP_O09_ORDER> zmp_o09_orders = zmp_o09.getORDERAll(); for (ZMP_O09_ORDER zmp_o09_order : zmp_o09_orders) { ORC orc = zmp_o09_order.getORC(); Z01 z01 = zmp_o09_order.getZ01(); TQ1 tq1 = zmp_o09_order.getTIMING().getTQ1(); RXC rxc = zmp_o09_order.getCOMPONENT().getRXC(); //ORC.21.10 - OrganizationIdentifier if (StringUtils .isBlank(orc.getOrderingFacilityName(0).getOrganizationIdentifier().getValue())) { //ORC.21.10 throw new HL7Exception( "No se ha indicado el centro de origen (ORC-21.10: OrganizationIdentifier)"); } else { cod_centro = orc.getOrderingFacilityName(0).getOrganizationIdentifier().getValue(); } //ORC.2.1 - Codigo de Prescripcion if (StringUtils.isBlank(orc.getPlacerOrderNumber().getEntityIdentifier().getValue())) { throw new HL7Exception( "No se ha indicado el identificador de la prescripcion (ORC-2.1: Placer Order Number)"); } //ORC.10 - Medico Prescriptor if (StringUtils.isBlank(orc.getEnteredBy(0).getIDNumber().getValue())) { //ORC.10.1 throw new HL7Exception( "No se ha indicado el codigo del medico prescriptor (ORC-10.1: Entered By)"); } if (StringUtils.isBlank(orc.getEnteredBy(0).getGivenName().getValue())) { //ORC.10.3 throw new HL7Exception( "No se ha indicado el nombre del medico prescriptor (ORC-10.3: Entered By)"); } if (StringUtils.isBlank(orc.getEnteredBy(0).getFamilyName().getSurname().getValue())) { //ORC.10.2.1 throw new HL7Exception( "No se ha indicado el apellido del medico prescriptor (ORC-10.2.1: Entered By)"); } //RXC.2.1 - DispenseGiveCode (Codigo Nacional de la Marca) if (StringUtils.isBlank(rxc.getComponentCode().getIdentifier().getValue())) { //RXC.2.1 throw new HL7Exception( "No se ha indicado el codigo nacional de la marca (RXC-2.1: ComponentCode)"); } //RXC.2.2 - DispenseGiveCode (Descripcion de la Marca) if (StringUtils.isBlank(rxc.getComponentCode().getText().getValue())) { //RXC.2.2 throw new HL7Exception("No se ha indicado la descripcion de la marca (RXC-2.2: Text)"); } //TQ1.7 - Fecha de Inicio de la Prescripcion if (StringUtils.isBlank(tq1.getStartDateTime().getTime().getValue())) { throw new HL7Exception( "No se ha indicado la fecha de inicio de la prescripcion (TQ1-7: Start date/time)"); } //TQ1.8 - Fecha de Fin de la Prescripcion if (StringUtils.isBlank(tq1.getEndDateTime().getTime().getValue())) { throw new HL7Exception( "No se ha indicado la fecha de fin de la prescripcion (TQ1-8: End date/time)"); } //Z01.9 - Dosis Prescrita en Unidad de Medida if (StringUtils.isNotBlank(z01.getDosisPrescrita().getValue())) { //Z01.9 try { NumberUtils.createDouble(z01.getDosisPrescrita().getValue()); } catch (Exception e) { throw new HL7Exception( "La dosis prescrita no es correcta [" + z01.getDosisPrescrita().getValue() + "] (Z01-9: Dosis Prescrita en Unidad de Medida)"); } } else { throw new HL7Exception( "No se ha indicado dosis prescrita (Z01-9: Dosis Prescrita en Unidad de Medida)"); } } } else if (hl7message.getClass() == ZFN_M13.class) { //RESPUESTAS DE EVALUACIONES ZFN_M13 zfn_m13 = (ZFN_M13) hl7message; ZFA zfa = zfn_m13.getACUERDO().getZFA(); //ZFA.1.1 - MasterIdentifier if (StringUtils.isBlank(zfa.getMasterIdentifier().getAlternateIdentifier().getValue())) { //ZFA.1.1 throw new HL7Exception("No se ha indicado el codigo de acuerdo (ZFA.1.1: AlternateIdentifier)"); } //ZFA.2.1 - Master file application identifier if (StringUtils.isBlank(zfa.getMasterFileApplicationIdentifier().getNamespaceID().getValue())) { //ZFA.2.1 throw new HL7Exception("No se ha indicado el centro de origen (ZFA.2.1: NamespaceID)"); } else { cod_centro = zfa.getMasterFileApplicationIdentifier().getNamespaceID().getValue(); } } else if (hl7message.getClass() == RAS_O17.class) { //RESPUESTAS DE EVALUACIONES RAS_O17 ras_o17 = (RAS_O17) hl7message; PID pid = ras_o17.getPATIENT().getPID(); PV1 pv1 = ras_o17.getPATIENT().getPATIENT_VISIT().getPV1(); //PID.3 - Identificadores del paciente (NHC) y (CIPA) Integer nhc = null; String cipa = null; for (int i = 0; i < pid.getPatientIdentifierList().length; i++) { // PID.3 - PatientIdentifierList if (StringUtils.equalsIgnoreCase( pid.getPatientIdentifierList(i).getIdentifierTypeCode().getValue(), "PI")) { if (StringUtils.isNotBlank(pid.getPatientIdentifierList(i).getIDNumber().getValue())) { try { nhc = NumberUtils .createInteger(pid.getPatientIdentifierList(i).getIDNumber().getValue()); } catch (Exception e) { throw new HL7Exception("El NHC no es correcto (PID-3.1: Patient Identifier List)"); } } else { throw new HL7Exception("No se ha indicado el NHC (PID-3.1: Patient Identifier List)"); } } else if (StringUtils.equalsIgnoreCase( pid.getPatientIdentifierList(i).getIdentifierTypeCode().getValue(), "CIPA")) { if (StringUtils.isBlank(pid.getPatientIdentifierList(i).getIDNumber().getValue())) { throw new HL7Exception("El CIPA no es correcto (PID-3.1: Patient Identifier List)"); } else { cipa = pid.getPatientIdentifierList(i).getIDNumber().getValue(); } } } if (nhc == null) { throw new HL7Exception("No se ha indicado el NHC (PID-3.1: Patient Identifier List)"); } if (StringUtils.isBlank(cipa)) { throw new HL7Exception("No se ha indicado el CIPA (PID-3.1: Patient Identifier List)"); } //PV1.2 - Clase de Paciente if (StringUtils.isNotBlank(pv1.getPatientClass().getValue())) { //PV1.2 - Clase de Paciente if (StringUtils.equals(pv1.getPatientClass().getValue(), "O")) { //Outpatient if (StringUtils.isBlank(pv1.getPatientType().getValue())) { //PV1.18 - Tipo de Paciente throw new HL7Exception("No se ha indicado el tipo de paciente (PV1-18: Patient Type)"); } } } else { throw new HL7Exception("No se ha indicado la clase de paciente (PV1-2: Patient Class)"); } //PV1.19.1 - Codigo de Episodio if (StringUtils.isBlank(pv1.getVisitNumber().getIDNumber().getValue())) { throw new HL7Exception("No se ha indicado el episodio del paciente (PV1.19: Visit Number)"); } List<RAS_O17_ORDER> ras_o17_orders = ras_o17.getORDERAll(); for (RAS_O17_ORDER ras_o17_order : ras_o17_orders) { ORC orc = ras_o17_order.getORC(); TQ1 tq1 = ras_o17_order.getTIMING().getTQ1(); RXO rxo = ras_o17_order.getORDER_DETAIL().getRXO(); RXA rxa = ras_o17_order.getADMINISTRATION().getRXA(); //ORC.21.10 - OrganizationIdentifier if (StringUtils .isBlank(orc.getOrderingFacilityName(0).getOrganizationIdentifier().getValue())) { //ORC.21.10 throw new HL7Exception( "No se ha indicado el centro de origen (ORC-21.10: OrganizationIdentifier)"); } else { cod_centro = orc.getOrderingFacilityName(0).getOrganizationIdentifier().getValue(); } //ORC.2.1 - Codigo de Prescripcion if (StringUtils.isBlank(orc.getPlacerOrderNumber().getEntityIdentifier().getValue())) { throw new HL7Exception( "No se ha indicado el identificador de la prescripcion (ORC-2.1: Placer Order Number)"); } //ORC.3.1 - Codigo de Administracion if (StringUtils.isBlank(orc.getFillerOrderNumber().getEntityIdentifier().getValue())) { throw new HL7Exception( "No se ha indicado el identificador de la administracion (ORC-3.1: Filler Order Number)"); } //ORC.10 - Medico Prescriptor if (StringUtils.isBlank(orc.getEnteredBy(0).getIDNumber().getValue())) { //ORC.10.1 throw new HL7Exception( "No se ha indicado el codigo del medico prescriptor (ORC-10.1: Entered By)"); } if (StringUtils.isBlank(orc.getEnteredBy(0).getGivenName().getValue())) { //ORC.10.3 throw new HL7Exception( "No se ha indicado el nombre del medico prescriptor (ORC-10.3: Entered By)"); } if (StringUtils.isBlank(orc.getEnteredBy(0).getFamilyName().getSurname().getValue())) { //ORC.10.2.1 throw new HL7Exception( "No se ha indicado el apellido del medico prescriptor (ORC-10.2.1: Entered By)"); } //TQ1.7 - Fecha de Inicio de la Prescripcion if (StringUtils.isBlank(tq1.getStartDateTime().getTime().getValue())) { throw new HL7Exception( "No se ha indicado la fecha de inicio de la prescripcion (TQ1-7: Start date/time)"); } //RXA.3 - Fecha de la Administracion if (StringUtils.isBlank(rxa.getDateTimeStartOfAdministration().getTime().getValue())) { throw new HL7Exception( "No se ha indicado la fecha de la adminsitracion (RXA-3: Start date/time)"); } //RXA.5 - Marca if (StringUtils.isBlank(rxa.getAdministeredCode().getIdentifier().getValue())) { //RXA.5.1 throw new HL7Exception( "No se ha indicado el codigo nacional de la marca (RXA-5.1: AdministeredCode)"); } //RXA.6 - Dosis Administrada en Forma Farmaceutica if (StringUtils.isNotBlank(rxa.getAdministeredAmount().getValue())) { //RXA.6 try { NumberUtils.createDouble(rxa.getAdministeredAmount().getValue()); } catch (Exception e) { throw new HL7Exception("La dosis administrada no es correcta [" + rxa.getAdministeredAmount().getValue() + "] (ZRA-6: Dosis Administrada en Forma Farmaceutica)"); } } else { throw new HL7Exception( "No se ha indicado dosis administrada (RXA-6: Dosis Administrada en Forma Farmaceutica)"); } //RXO.2 - Dosis Prescrita en Unidad de Medida if (StringUtils.isNotBlank(rxo.getRequestedGiveAmountMinimum().getValue())) { //RXO.2 try { NumberUtils.createDouble(rxo.getRequestedGiveAmountMinimum().getValue()); } catch (Exception e) { throw new HL7Exception("La dosis prescrita no es correcta [" + rxo.getRequestedGiveAmountMinimum().getValue() + "] (RXO-2: Dosis Prescrita en Unidad de Medida)"); } } else { throw new HL7Exception( "No se ha indicado dosis prescrita (RXO-2: Dosis Prescrita en Unidad de Medida)"); } } } else { throw new HL7Exception("No se reconoce el tipo de mensaje (MSH.9 - Message Type)"); } // Validacion del codigo de centro Centros centros = new Centros(); centros.setCodCentro(cod_centro); try { centros = centrosService.findByCodCentro(centros); } catch (Exception e) { throw new HL7Exception( "No se reconoce el codigo de centro " + cod_centro + " (" + e.getMessage() + ")"); } logger.debug(" Almacenando el mensaje en BUZON_IN"); BuzonIn buzonIn = new BuzonIn(); buzonIn.setCentros(centros); buzonIn.setIdMensaje(msh.getMessageControlID().getValue()); //MSH.10 buzonIn.setMensaje(message); buzonIn.setFechaIn(new Date()); buzonIn.setEstado(AbstractIntegracionEntity.MENSAJE_NO_PROCESADO); buzonIn.setTipo(hl7message.getName()); buzonInService.save(buzonIn); logger.debug(" Mensaje almacenado en BUZON_IN correctamente"); ack = parser.generateACK(hl7message); } catch (Exception e) { try { logger.error("SE HAN PRODUCIDO ERRORES: " + e.toString()); if (e.getCause() != null && e.getCause().getClass() == ConstraintViolationException.class) { ack = parser.generateNACK(hl7message, "El mensaje con MSH.10: " + ((MSH) hl7message.get("MSH")).getMessageControlID().getValue() + " ya se encuentra en el sistema"); } else { ack = parser.generateNACK(hl7message, e.getMessage()); } } catch (Exception ex) { logger.error("SE HAN PRODUCIDO ERRORES: " + ex.toString()); ack = parser.generateNACK(hl7message, ex.getMessage() != null ? ex.getMessage() : ex.toString()); } } //Generar la respuesta String response; try { response = ack.encode(); } catch (Exception e) { logger.error("No se ha podido generar la respuesta: " + e.toString() + "\rGenerando respuesta tipo"); response = "MSH|^~\\&|MPR|mpr-ws|||" + DateFormatUtils.formatUTC(System.currentTimeMillis(), "yyyyMMddHHmmss") + "||ACK|" + System.currentTimeMillis() + "|P|2.5\r" + "MSA|AE\r" + "ERR||||E|||NO SE HA PODIDO GENERAR UNA RESPUESTA: " + e.getMessage() != null ? e.getMessage() : e.toString() + "\r"; } logger.debug(" Respuesta a generar: "); logger.debug(response); logger.info("RECEPCION DEL MENSAJE FINALIZADA"); return new ResponseEntity(response, HttpStatus.OK); }
From source file:com.epam.dlab.automation.helper.PropertiesResolver.java
private static void loadApplicationProperties() { InputStream input = null;/* w w w . ja va2 s . com*/ try { input = PropertiesResolver.class.getClassLoader().getResourceAsStream(CONFIG_FILE_NAME); // load a properties file properties.load(input); String rootPath = getConfRootPath(); for (String key : properties.keySet().toArray(new String[0])) { String path = StringUtils.replace(properties.getProperty(key), "${CONF_ROOT_PATH}", rootPath); path = Paths.get(path).toAbsolutePath().toString(); properties.setProperty(key, path); } overlapProperty(properties, CONF_FILE_LOCATION_PROPERTY, false); // get the property value and print it out LOGGER.info(properties.getProperty(CONF_FILE_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(KEYS_DIRECTORY_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(NOTEBOOK_TEST_DATA_COPY_SCRIPT)); LOGGER.info(properties.getProperty(NOTEBOOK_TEST_LIB_LOCATION)); LOGGER.info(properties.getProperty(SCENARIO_JUPYTER_FILES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(SCENARIO_RSTUDIO_FILES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(SCENARIO_ZEPPELIN_FILES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(SCENARIO_TENSOR_FILES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(SCENARIO_DEEPLEARNING_FILES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(JUPYTER_TEST_TEMPLATES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(RSTUDIO_TEST_TEMPLATES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(ZEPPELIN_TEST_TEMPLATES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(TENSOR_TEST_TEMPLATES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(DEEPLEARNING_TEST_TEMPLATES_LOCATION_PROPERTY)); LOGGER.info(properties.getProperty(CLUSTER_CONFIG_FILE_LOCATION_PROPERTY)); } catch (IOException ex) { LOGGER.error(ex); LOGGER.error("Application configuration file could not be found by the path: {}", CONFIG_FILE_NAME); System.exit(0); } finally { if (input != null) { try { input.close(); } catch (IOException e) { LOGGER.error(e); LOGGER.error("Application configuration file could not be found by the path: {}", CONFIG_FILE_NAME); } } } }
From source file:gov.nih.nci.firebird.common.FirebirdEnumUtils.java
/** * @param enumeration enumeration to convert * @return a String display of the enumeration. Replaces all "_" with spaces and capitalizes first letter of each * word./*from w w w .j a v a 2 s .co m*/ */ public static String getEnumDisplay(Enum<?> enumeration) { return WordUtils.capitalizeFully(StringUtils.replace(enumeration.name(), "_", " ")); }
From source file:com.qwazr.crawler.web.manager.CurrentURIImpl.java
@Override public void hrefToURICollection(Collection<String> hrefCollection, Collection<URI> uriCollection) { if (hrefCollection == null) return;/*from www . j a v a 2 s. co m*/ URI uri = baseURI != null ? baseURI : getURI(); for (String href : hrefCollection) { href = StringUtils.replace(href, " ", "%20"); URI resolvedURI = LinkUtils.resolveQuietly(uri, href); if (resolvedURI != null) uriCollection.add(resolvedURI); } }
From source file:com.xpn.xwiki.util.Util.java
public static String cleanValue(String value) { value = StringUtils.replace(value, "\r\r\n", "%_N_%"); value = StringUtils.replace(value, "\r\n", "%_N_%"); value = StringUtils.replace(value, "\n\r", "%_N_%"); value = StringUtils.replace(value, "\r", "\n"); value = StringUtils.replace(value, "\n", "%_N_%"); value = StringUtils.replace(value, "\"", "%_Q_%"); return value; }
From source file:com.xpn.xwiki.objects.classes.ListClass.java
public static Map<String, ListItem> getMapFromString(String value) { Map<String, ListItem> map = new HashMap<String, ListItem>(); if (value == null) { return map; }/*w w w.ja va 2s .c o m*/ String val = StringUtils.replace(value, "\\|", "%PIPE%"); String[] result = StringUtils.split(val, "|"); for (int i = 0; i < result.length; i++) { String element = StringUtils.replace(result[i], "%PIPE%", "|"); if (element.indexOf('=') != -1) { String[] data = StringUtils.split(element, "="); map.put(data[0], new ListItem(data[0], data[1])); } else { map.put(element, new ListItem(element, element)); } } return map; }
From source file:io.gs2.AbstractGs2Client.java
/** * POST?/*from w w w .j a va 2 s.c om*/ * * @param url URL * @param credential ? * @param service * @param module * @param function * @param body * @return */ protected HttpPut createHttpPut(String url, IGs2Credential credential, String service, String module, String function, String body) { Long timestamp = System.currentTimeMillis() / 1000; url = StringUtils.replace(url, "{service}", service); url = StringUtils.replace(url, "{region}", region.getName()); HttpPut put = new HttpPut(url); put.setHeader("Content-Type", "application/json"); credential.authorized(put, service, module, function, timestamp); put.setEntity(new StringEntity(body, "UTF-8")); return put; }
From source file:com.workday.autoparse.xml.demo.XmlParserTest.java
@Test public void testSetters() throws ParseException, UnexpectedChildException, UnknownElementException { XmlStreamParser parser = XmlStreamParserFactory.newXmlStreamParser(); InputStream in = getInputStreamOf("setter-input.xml"); SetterModel setterModel = (SetterModel) parser.parseStream(in); assertEquals(5, setterModel.anInt);//from ww w . ja va2 s . c om assertNotNull(setterModel.child); assertEquals(2, setterModel.repeatedChildren.size()); // Pull autoparse includes newlines and whitespace, so get rid of it here. assertEquals("Hello", StringUtils.trim(StringUtils.replace(setterModel.textContent, "\n", " "))); }