date to datetime with Hours between script POSTGRESQL - postgresql

This code can only capture the date, I want to capture all the time of day (sol.datahorafim = 00:00:00 to dataInicial = 23:55:55). How do I do this?
EDIT WITH PARAM from xml and function.
XML:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<PARAMETERS>
<PARAM name='dataInicial' type='java.sql.Date' size='10' value='' description='citcorpore.comum.datainicio' fix='false' mandatory='true' reload='true' />
<PARAM name='dataFinal' type='java.sql.Date' size='10' value='' description='citcorpore.comum.datafim' fix='false' mandatory='true' default='{TODAY}'/>
<PARAM name='contrato' type='java.lang.Integer' typeHTML='select' size='0'value='' description='Contrato' fix='false' mandatory='false' reload='true' onload='true'>
<OPTION value='-1' text='Todos'/>
<OPTIONS type='SQL' onload='true'>
SELECT idcontrato, numero+' '+nomefantasia
FROM contratos ct, clientes cl
where cl.idcliente = ct.idcliente
order by 2
</OPTIONS>
</PARAM>
<PARAM name='status' type='java.lang.Integer' typeHTML='select' size='0'value='' description='Status' fix='false' mandatory='false' reload='true' onload='true'>
<OPTION value='-1' text='Todos'/>
<OPTION value='6' text='Fechada'/>
<OPTION value='3' text='Cancelada'/>
</PARAM>
<PARAM name='executor' type='java.lang.String' value='' typeHTML='text' size='10' description='Executor' fix='false' mandatory='false'/>
<PARAM name='quantidade' type='java.lang.Integer' value='' typeHTML='text' size='10' description='Qtd Bases' fix='false' mandatory='false'/>
</PARAMETERS>
Function:
montarSql = function() {
var sql = new importNames.StringBuilder();
var parametroContrato = hashParametros.get("PARAM.contrato");
var parametroExecutor = hashParametros.get("PARAM.executor");
var parametroQuantidade = hashParametros.get("PARAM.quantidade");
var parametroStatus = hashParametros.get("PARAM.status");
sql.append("select idsolicitacaoservico,nomeservico,idstatus,qtd_conhecimentos, nome, grupo ");
sql.append("from ");
sql.append("(select con.numero,ser.nomeservico,sol.idsolicitacaoservico, sol.idstatus,");
sql.append("(select count(idBaseConhecimento) from conhecimentosolicitacaoservico where ");
sql.append("idsolicitacaoservico = sol.idsolicitacaoservico) qtd_conhecimentos, usu.nome, gr.nome grupo ");
sql.append("from solicitacaoservico sol INNER JOIN servicocontrato scn ON sol.idservicocontrato = scn.idservicocontrato ");
sql.append("JOIN servico ser ON scn.idservico = ser.idservico ");
sql.append("JOIN contratos con ON scn.idcontrato = con.idcontrato ");
sql.append("join bpm_itemtrabalhofluxo ite on ite.iditemtrabalho = sol.idtarefaencerramento ");
sql.append("left join usuario usu on usu.idusuario = ite.idresponsavelatual ");
sql.append("left join grupo gr on gr.idgrupo = sol.idgrupoatual ");
sql.append("where ")
if (parametroExecutor != ""){
sql.append(" emp.nome like '%");sql.append(parametroExecutor);sql.append("%' and ");
}
if(parametroContrato!="-1"){
sql.append("(con.idcontrato = {PARAM.contrato}) and ");
}
if(parametroStatus !="-1"){
sql.append(" sol.idstatus = ");sql.append(parametroStatus );sql.append(" and ");
}
sql.append(" sol.datahorafim BETWEEN {PARAM.dataInicial} and {PARAM.dataFinal} ) bs ");
I try see documentation but nothing exactly what I want

Your description is not quite clear, but maybe you want to compare like this:
WHERE date_trunc('day', sol.datahorafim) BETWEEN ... AND ...

Related

AZURE API management JWT-token validation (IDX10511: Signature validation failed)

I have created my own identity server, which issued/makes tokens based on username and code. It works locally between app service to app service, but when I try to validate the token on AZURE API management fails.
I think the error is in openid-config but can see what is wrong.
But gets this error:
IDX10511: Signature validation failed. Keys tried: 'Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: 'AanrD1WcPkqMpK3p2S0JQ7ixqWkYBAL8hRnU6Dciiew', InternalId: 'b7aZZOAAhueurq_c62cqJcTBXL69skl6hu1a1oHLu1w'. , KeyId: AanrD1WcPkqMpK3p2S0JQ7ixqWkYBAL8hRnU6Dciiew
'.
kid: 'AanrD1WcPkqMpK3p2S0JQ7ixqWkYBAL8hRnU6Dciiew'.
Exceptions caught:
''.
token: '{"alg":"RS256","kid":"AanrD1WcPkqMpK3p2S0JQ7ixqWkYBAL8hRnU6Dciiew","typ":"JWT"}.{"nbf":1624878880,"exp":1627470880,"iss":"https://login.zenbi.dk","aud":"You"}'.
Token: eyJhbGciOiJSUzI1NiIsImtpZCI6IkFhbnJEMVdjUGtxTXBLM3AyUzBKUTdpeHFXa1lCQUw4aFJuVTZEY2lpZXciLCJ0eXAiOiJKV1QifQ.eyJuYmYiOjE2MjQ4Nzg4ODAsImV4cCI6MTYyNzQ3MDg4MCwiaXNzIjoiaHR0cHM6Ly9sb2dpbi56ZW5iaS5kayIsImF1ZCI6IllvdSJ9.Lm32InrGT5DfphZalI9oQPzm-jcNDsOTGGkhE0dpdhdL7xpcVuZ4go6-i1dDx_cri7Neh4cow9vv3JR_Q75qhmVEr9TVrbAXP1Spkz0uvJPa9pLsQIZxH6B5D1ICnC0ROjgr5PQFXbMJXAYPludai5GpJWtX7ufUvFjauW2p2l1ssuK1iB27YeuYw7IDpMbgQvzlgVvqD8E4dzFoWdq-kLF8ZP-A3qnAtEchXu5JVJg4d7o3gI--cqJ7RaF6ehzVvFHvgADw54j4Gniif-mjnLDCZU0CYDMfRGmt5kURSJSvJUXZtaJgKYa9eQ0jSib6At4LZUVGYlHxx_I5jtjd3w
<policies>
<inbound>
<base />
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="#((string)context.LastError.Message)" require-scheme="Bearer" require-signed-tokens="true">
<openid-config url="https://zenbicertificates.blob.core.windows.net/jwt/openid-configuration.json" />
</validate-jwt>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
</policies>
How about writing validate logic by yourself ?
<set-variable name="pass" value="#{
bool isAud = false;
bool isIss = false;
string pass = "false";
string authHeader = context.Request.Headers.GetValueOrDefault("Authorization", "");
if (authHeader?.Length > 0)
{
string[] authHeaderParts = authHeader.Split(' ');
if (authHeaderParts?.Length == 2 && authHeaderParts[0].Equals("Bearer", StringComparison.InvariantCultureIgnoreCase))
{
Jwt jwt;
if (authHeaderParts[1].TryParseJwt(out jwt))
{
string tempScp = jwt.Claims.GetValueOrDefault("scp", "null");
if(tempScp != "null"){
isAud = tempScp.Contains("YOU");
}
string tempIss = jwt.Claims.GetValueOrDefault("iss", "null");
if(tempIss != "null"){
isIss = tempIss.Contains("xxx");
}
}
}
}
if(isAud || isIss ){
pass = "true";
}
return pass;
}" />
<choose>
<when condition="#(context.Variables.GetValueOrDefault("pass") == "false")">
<return-response response-variable-name="existing response variable">
<set-status code="401" reason="Unauthorized hhh" />
</return-response>
</when>
<otherwise />
</choose>

Criteria MongoTemplate achieve the query with not none conditions

I am a beginner in Spring MongoDB Criteria.
Once my database was mysql,if the variable is not none,I can do not none query like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.mytest.modules.system.mapper.SysUserMapper">
<select id="getSysUser" resultType="org.mytest.modules.system.entity.SysUser">
select * from sys_user where del_flag = 0
<if test="username!=null and username!=''">
and username = #{username}
</if>
<if test="age!=null and age!=''">
and age = #{age}
</if>
<if test="profession!=null and profession!=''">
and profession = #{profession}
</if>
<if test="education!=null and education!=''">
and education = #{education}
</if>
<if test="dateStart!=null">
<![CDATA[ and DATE_FORMAT(time, '%Y-%m-%d %H:%T:%s') >=
DATE_FORMAT(#{dateStart} , '%Y-%m-%d %H:%T:%s') ]]>
</if>
<if test="dateEnd!=null">
<![CDATA[ and DATE_FORMAT(time, '%Y-%m-%d %H:%T:%s') <=
DATE_FORMAT(#{dateEnd} , '%Y-%m-%d %H:%T:%s') ]]>
</if>
</select>
</mapper>
Now my database change to mongoDB.How to do it with Criteria MongoTemplate with Criteria().andOperator?
SysUser sysUser = new SysUser();
// Create criteria object
Criteria criteria = Criteria.where("del_flag").is(0);
// Judge one by one
if (StringUtils.hasLength(sysUser.getUsername())) {
criteria = criteria.and("username").is(sysUser.getUsername());
}
if (Objects.nonNull(sysUser.getAge())) {
criteria = criteria.and("age").is(sysUser.getAge());
}
if (StringUtils.hasLength(sysUser.getProfession())) {
criteria = criteria.and("profession").is(sysUser.getProfession());
}
if (StringUtils.hasLength(sysUser.getEducation())) {
criteria = criteria.and("education").is(sysUser.getEducation());
}
if (Objects.nonNull(sysUser.getDateStart())) {
criteria = criteria.and("dateStart").gte(sysUser.getDateStart());
}
if (Objects.nonNull(sysUser.getDateEnd())) {
criteria = criteria.and("dateEnd").lte(sysUser.getDateEnd());
}
Query query = new Query(criteria);
List<SysUser> sysUserList = mongoTemplate.find(query, SysUser.class, "sys_user");

Odoo 10 : Failed to render mail template

I have created an mail template in Odoo 10, and call it with a cron task. The problem is that it doesn't work and give me error, here is the log : https://pastebin.com/c7zCXbxF. Could you help me?
Here is the mail template:
<odoo>
<data>
<record id="crm_lead_reminder" model="mail.template">
<field name="name">Rappel sur le pipeline</field>
<field name="email_from">admin#example.com</field>
<field name="subject">Rappel ${object.type} ${object.name} </field>
<field name="email_to">${object.user_id.partner_id.email}</field>
<field name="model_id" ref="sale_cron.model_crm_lead"/>
<field name="auto_delete" eval="True"/>
<field name="body_html">
<![CDATA[
<p>
hello world
</p>
]]>
</field>
</record>
</data>
And here is the methode that call it:
class sale_cron(models.Model):
_inherit = 'crm.lead'
def _trigger_action(self, date_action, current_date):
date_action = [int(date) for date in date_action.split('-')]
if date_action[0] == current_date.year:
if date_action[1] == current_date.month:
if date_action[2] == current_date.day or date_action[2] == current_date.day + 1:
return 0
return -1
def _check_crm_lead(self):
current_date = datetime.datetime.now()
for crm_lead_id in self.search([('stage_id', '!=', 4)]):
i = self._trigger_action(crm_lead_id.date_action, current_date)
if i == -1:
return 0
template = self.env.ref('sale_cron.crm_lead_reminder')
template.send_mail(self.user_id.id, force_send=True, raise_exception=True)
return 1
ps: the module name is sale_cron.
Try changing your code like this
template.send_mail(crm_lead_id.id, force_send=True, raise_exception=True)
def _check_crm_lead(self):
current_date = datetime.datetime.now()
for crm_lead_id in self.search([('stage_id', '!=', 4)]):
i = self._trigger_action(crm_lead_id.date_action, current_date)
if i == -1:
return 0
template = self.env.ref('sale_cron.crm_lead_reminder')
template.send_mail(crm_lead_id.id, force_send=True, raise_exception=True)
return 1

copy rows with myBatis

I'm trying to copy rows with Oracle and myBatis with this statement:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
...
<insert id="copy" >
INSERT INTO ${table}
<foreach item="key" collection="keys" index="index" open="(" separator="," close=")">
${key}
</foreach>
VALUES
<foreach item="key" collection="map" index="index" open="(" separator="," close=")">
${key}
</foreach>
</insert>
</mapper>
--
for ( Map.Entry<Object, Object> entry2 : map.entrySet()) {
String key2 = (String) entry2.getKey();
Object value = null;
if (entry2.getValue() == null)
value = "NULL";
else if (entry2.getValue() instanceof java.sql.Timestamp)
{
//...
}
else if (entry2.getValue() instanceof Integer || entry2.getValue() instanceof Long ||
entry2.getValue() instanceof Short || entry2.getValue() instanceof java.math.BigDecimal
){
value = entry2.getValue();
}
else if (entry2.getValue().getClass().getName().equals("oracle.sql.CLOB"))
{
Clob clob=(Clob)entry2.getValue();
value= (String)clob.getSubString((long)1, (int)clob.length());
}
else{
value = "'" + entry2.getValue() + "'";
}
map.put(key2, value);
columans_valores.add("'" + key2 + "'");
}
copyService(map, map.keySet(), "table");
--
It works with most types, but CLOB and BLOB get their address copied instead or gets shrunk to 4000 bytes depending on the code i use to copy them, how do i deal with them?
Finally got it working with some tweaks:
To inform myBatis about the type used, switch $ for #
Avoid quotes
To prevent Oracle errors when inserting nulls, remove them from the map instead of
trying to insert null values

Magento rest api getting error Request does not match any route

I have created a rest api web service but I am getting error on hitting the url
http://localhost:81/magento/api/rest/category/2
<magento_api>
<messages>
<error>
<data_item>
<code>404</code>
<message>Request does not match any route.</message>
</data_item>
</error>
</messages>
</magento_api>
My api2.xml is:-
<?xml version="1.0"?>
<config>
<api2>
<resource_groups>
<esoft_rescategories translate="title" module="Esoft_Restcategories">
<title>Esoft Restcategories API</title>
<sort_order>11</sort_order>
</esoft_rescategories>
</resource_groups>
<resources>
<esoft_restcategories translate="title" module="Esoft_Restcategories">
<group>esoft_rescategories</group>
<model>esoft_restcategories/api2_restapi</model>
<title>Categories</title>
<sort_order>11</sort_order>
<privileges>
<admin>
<create>1</create>
<!--<retrieve>1</retrieve>
<update>1</update>
<delete>1</delete>-->
</admin>
<guest>
<retrieve>1</retrieve>
<!--<create>1</create>
<update>1</update>
<delete>1</delete>-->
</guest>
</privileges>
<attributes>
<category_id>Category ID</category_id>
<name>Name</name>
<parent_id>Category Parent ID</parent_id>
<child_id>Category Child List</child_id>
<active>Active</active>
<level>Level</level>
<position>Position</position>
</attributes>
<routes>
<route_entity>
<route>/categories/:cat_id</route>
<action_type>entity</action_type>
</route_entity>
<route_collection>
<route>/categories</route>
<action_type>collection</action_type>
</route_collection>
</routes>
<versions>1</versions>
</esoft_restcategories>
</resources>
</api2>
</config>
My version file for guest is:-
<?php
class Esoft_Restcategories_Model_Api2_Restapi_Rest_Guest_V1 extends Esoft_Restapi_Model_Api2_Restapi {
/**
* Retrieve list of category list.
*
* #return array
*/
protected function _retrieveCollection()
{
$ruleId = $this->getRequest()->getParam('cat_id');
// $cat_mod = Mage::getModel('catalog/category')->load($ruleId)->toArray();
$cats = Mage::getModel('catalog/category')->load($ruleId);
$subcats = Mage::getModel('catalog/category')->load($ruleId)->getChildren();
$cur_category = array();
$node['category_id'] = $ruleId;
$node['name'] = $cats->getName();
$node['parent_id'] = $cats->getParentId();
$node['child_id'] = $subcats;
if($cats->getIsActive()){
$node['active'] = 1;
}else{
$node['active'] = 0;
}
$node['level'] = $cats->getLevel();
$node['position'] = $cats->getPosition();
$cur_category[] = $node;
// $subcats = Mage::getModel('catalog/category')->load($ruleId)->getAllChildren();
// $subcats = Mage::getModel('catalog/category')->load($ruleId)->getChildren();
if($subcats != '')
{
foreach(explode(',',$subcats) as $subCatid)
{
$_category = Mage::getModel('catalog/category')->load($subCatid);
$childcats = Mage::getModel('catalog/category')->load($subCatid)->getChildren();
$node['category_id'] = $subCatid;
$node['name'] = $_category->getName();
$node['parent_id'] = $_category->getParentId();
$node['child_id'] = $childcats;
if($_category->getIsActive()){
$node['active'] = 1;
}else{
$node['active'] = 0;
}
$node['level'] = $_category->getLevel();
$node['position'] = $_category->getPosition();
$cur_category[] = $node;
}
}
return $cur_category;
}
}
Please let me know how to fix this error.
Also let me know on what basis we define routes.
Simple answer for those searching for cause of this error:
Request does not match any route
Is that you are posting the wrong METHOD such as GET/POST/PUT/DELETE.
It could also be the path of the API url itself is wrong.
As per your description your url format is wrong (route miss matching in given url).
<route>/categories/:cat_id</route>
^^^^^^^^^
So you need to change the url like below
http://localhost:81/magento/api/rest/categories/2