How to access the values only in flutter map - flutter

"turf_amenities": {
"turf_washroom": true,
"turf_water": true,
"turf_dressing": false,
"turf_parking": true,
"turf_gallery": true,
"turf_cafeteria": true
},

You can get the bool list like
final bools = data["turf_amenities"]?.values.toList();
print(bools);
final data = {
"turf_amenities": {
"turf_washroom": true,
"turf_water": true,
"turf_dressing": false,
"turf_parking": true,
"turf_gallery": true,
"turf_cafeteria": true
},
};
final values = data.values.toList();
print(
values); //[{turf_washroom: true, turf_water: true, turf_dressing: false, turf_parking: true, turf_gallery: true, turf_cafeteria: true}]
final bools = data["turf_amenities"]?.values.toList();
print(bools); //[true, true, false, true, true, true]

Related

How to reverse Map values in dart

I am trying to reverse Map values. But didin't get proper one,
here my Map
Map<String, dynamic> details = {
"sms": {
"very_low": false,
"low": false,
"medium": false,
"high": false,
"very_high": true
}
};
I want to get like this ;
{
sms: {
very_high: true,
high: false,
medium: false,
low: false,
very_low: false
}
}
If Anyone please share your ideas
Let's say this is your "map":
Map<String, dynamic> details = {
"sms": {
"very_low": false,
"low": false,
"medium": false,
"high": false,
"very_high": true
}
};
You can use this extension:
extension NewMap on Map {
Map reverse() => Map.fromEntries(entries.toList().reversed);
}
and use it like this:
details["sms"] = (details["sms"] as Map<String, dynamic>).reverse();
print("details =$details"); //details = {sms: {very_high: true, high: false, medium: false, low: false, very_low: false}}
A solution that works for any Map no matter how much nested it is:
Object reverse(Object object) {
if (object is Map) {
return Map.fromEntries(object.entries.map((e) => MapEntry(e.key, reverse(e.value))).toList().reversed);
}
return object;
}
usage:
void main() async {
Map<String, dynamic> details = {
"sms": {
"very_low": false,
"low": false,
"medium": false,
"high": false,
"very_high": true
}
};
var newDetails = reverse(details);
print(details);
//{sms: {very_low: false, low: false, medium: false, high: false, very_high: true}}
print(newDetails);
//{sms: {very_high: true, high: false, medium: false, low: false, very_low: false}}
}
final details =
{"sms" : {"very_low" : false, "very_hight" : true, "very_medium" : false} };
final outerMap = {};
for(final m in details.entries){
final reversedList = m.value.entries.toList().reversed;
final innerMap = {};
innerMap.addEntries(reversedList);
outerMap.addAll({m.key : innerMap});
}
print(outerMap);
//details = {sms: {very_medium: false, very_hight: true, very_low: false}}
import 'dart:convert';
Map<String, dynamic> yourMap = {
"sms": {
"very_low": false,
"low": false,
"medium": false,
"high": false,
"very_high": true
}
};
Map<K, V> reverse<K, V>(Map<K, V> source) {
return Map<K, V>.fromEntries(source.entries.toList().reversed);
}
main() {
print(jsonEncode(yourMap));
yourMap['sms'] = reverse(yourMap['sms']);
print(jsonEncode(yourMap));
}
Prints:
{"sms":{"very_low":false,"low":false,"medium":false,"high":false,"very_high":true}}
{"sms":{"very_high":true,"high":false,"medium":false,"low":false,"very_low":false}}
Please note that this only works because Map behind the scenes constructs a LinkedHashMap that is insertion-ordered. If you construct other types of Map that are not, this may not work. Generally speaking, it might be wise to not rely on the order of items in a Map because it is not guaranteed unless you created the Map yourself.
Since this looks like it should be JSON: don't bother sorting this. It is supposed to be a machine-to-machine protocol, machines do not care if it looks neat. The less uneccessary code you write, the less bugs you produce.

Find index of all true inside massive

I've an array of booleans there are 10 trues and falses and I want to know the index of all trues
var trueAndFalses = [false, false, true, false, false, false, true, false, false, false]
I tried firstIndex but it only returns the firstIndex ( yes kinda ironic ). now I wonder is there any built in functions to find all the indexes of true
print(trueAndFalses.firstIndex(of: true))
any solution will be appericated <3
You can try to find all index by visiting all elements and checking if its true like below:
var trueAndFalses = [false, false, true, false, false, false, true, false, false, false]
for var i in (0..<trueAndFalses.count){
if (trueAndFalses[i] == true)
{
print("true fount at index ",i)
}
}
Output:
true fount at index 2
true fount at index 6
Other way:
let indices = trueAndFalses.enumerated().compactMap { $1 == true ? $0 : nil }
print(indices)
Output:
[2, 6]

how to schedule a pgagent job through scripts/commandLine

I want to run jobs through PgAgent.
I am able to do that by creating a job in PgAgentJob through PgAdmin UI, as described here https://www.pgadmin.org/docs/pgadmin4/dev/pgagent_jobs.html.
But I want to use a sql script that can create a PgAgent job as we do in Oracle. Please suggest how I can achieve this.
To create a job in pgAgent use something like the following INSERT STATEMENTS (for a Routine Maintenance job) :
INSERT INTO pgagent.pga_job (jobid, jobjclid, jobname, jobdesc, jobenabled, jobhostagent)
SELECT jcl.jclid, 'MyJob', '', true, ''
FROM pgagent.pga_jobclass jcl WHERE jclname='Routine Maintenance';
To add a step to this job, which executes a SQL command ('delete from test where user_name=''test'';), use the following command:
INSERT INTO pgagent.pga_jobstep (jstjobid, jstname, jstdesc, jstenabled, jstkind, jstonerror, jstcode, jstdbname, jstconnstr)
SELECT (SELECT jobid
FROM pgagent.pga_job
WHERE jobname = 'MyJob'), 'MyStep', '', true, 's', 'f', 'delete from test where user_name=''test'';', 'postgres', '';
To create a schedule for this job (every day at 08:45), use the following command:
INSERT INTO pgagent.pga_schedule (jscjobid, jscname, jscdesc, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths, jscenabled, jscstart, jscend)
VALUES((SELECT jobid
FROM pgagent.pga_job
WHERE jobname = 'MyJob'), 'MySchedule', '', '{f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,t,f,f,f,f,f,f,f,f,f,f,f,f,f,f}',
'{f,f,f,f,f,f,f,f,t,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', '{t,t,t,t,t,t,t}', '{t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t}',
'{t,t,t,t,t,t,t,t,t,t,t,t}', true, '2018-07-16 00:00:00', NULL);
Here a graphical representation of this schedule:
Here you can see a complete summary of these commands inside an anonymous block (generated by pgAdmin):
DO $$
DECLARE
jid integer;
scid integer;
BEGIN
-- Creating a new job
INSERT INTO pgagent.pga_job(
jobjclid, jobname, jobdesc, jobhostagent, jobenabled
) VALUES (
1::integer, 'MyJob'::text, ''::text, ''::text, true
) RETURNING jobid INTO jid;
-- Steps
-- Inserting a step (jobid: NULL)
INSERT INTO pgagent.pga_jobstep (
jstjobid, jstname, jstenabled, jstkind,
jstconnstr, jstdbname, jstonerror,
jstcode, jstdesc
) VALUES (
jid, 'MyStep'::text, true, 's'::character(1),
''::text, 'postgres'::name, 'f'::character(1),
'delete from test where user_name=''test'';'::text, ''::text
) ;
-- Schedules
-- Inserting a schedule
INSERT INTO pgagent.pga_schedule(
jscjobid, jscname, jscdesc, jscenabled,
jscstart, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths
) VALUES (
jid, 'MySchedule'::text, ''::text, true,
'2018-07-16 00:00:00+02'::timestamp with time zone,
-- Minutes
ARRAY[false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false]::boolean[],
-- Hours
ARRAY[false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]::boolean[],
-- Week days
ARRAY[true, true, true, true, true, true, true]::boolean[],
-- Month days
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]::boolean[],
-- Months
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true]::boolean[]
) RETURNING jscid INTO scid;
END
$$;

How to schedule timing for a JOB in Postgres using pgagent

I have created a job using pgagent which I have scheduled on every 5 mins for that below is the code:
DO $$
DECLARE
jid integer;
scid integer;
BEGIN
-- Creating a new job
INSERT INTO pgagent.pga_job(
jobjclid, jobname, jobdesc, jobhostagent, jobenabled
) VALUES (
1::integer, 'refresh_mobile'::text, ''::text, ''::text, true
) RETURNING jobid INTO jid;
-- Steps
-- Inserting a step (jobid: NULL)
INSERT INTO pgagent.pga_jobstep (
jstjobid, jstname, jstenabled, jstkind,
jstconnstr, jstdbname, jstonerror,
jstcode, jstdesc
) VALUES (
jid, 'refresh_mobile_mv_data'::text, true, 's'::character(1),
''::text, 'ICSPGD'::name, 'f'::character(1),
'SELECT refresh_materialized_views(''mobile'');'::text, 'Please check. Issue occired while refreshing Mobile Data'::text
) ;
-- Schedules
-- Inserting a schedule
INSERT INTO pgagent.pga_schedule(
jscjobid, jscname, jscdesc, jscenabled,
jscstart, jscend, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths
) VALUES (
jid, 'minutly'::text, ''::text, true,
'2017-09-04 03:36:20-07'::timestamp with time zone, '2018-12-31 02:36:20-08'::timestamp with time zone,
-- Minutes
ARRAY[false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]::boolean[],
-- Hours
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]::boolean[],
-- Week days
ARRAY[true, true, true, true, true, true, true]::boolean[],
-- Month days
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]::boolean[],
-- Months
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true]::boolean[]
) RETURNING jscid INTO scid;
END
$$;
But when I am checking its statistics(in pgadmin) or via query "select * from pgagent.pga_job;" it shows that job are running at an interval of 1 hour.
For example: If the last job run time is 2017-10-05 03:05:00.703287-07 , then the next run time it shows : 2017-10-05 04:05:00-07.
Kindly help with the timing parameter. I am suppose to run this job on an interval of every 5 mins on a daily basis throughout.
Regards,
Have you tried something like this?
INSERT INTO pgagent.pga_schedule
(jscid, jscjobid, jscname, jscdesc, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths, jscenabled, jscstart, jscend)
VALUES(<SchId>, 29, 'minutly', '', '{t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f}', '{f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', '{f,f,f,f,f,f,f}', '{f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', '{f,f,f,f,f,f,f,f,f,f,f,f}', true, '2017-10-07 00:00:00', NULL);
Basically, what this insert is doing is marking the minutes 0,5,10,15,20,25,30,35,40,45,50 and 55 for every hour.
I don't know why you're creating it using insert statements, since the GUI offers a pretty neat way to schedule jobs. The same configuration can be done using the GUI like this:
I hope it helps :-)

Error while loading serialization policy

I have a problem with my gwt project.
I've instantiated my project on two TomCat servers, and when I try to communicate server to server, Eclipse returns this error:
Jul 23, 2013 4:23:02 PM org.apache.catalina.core.ApplicationContext log
SEVERE: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract int it.ronf.client.RonfService.checkCarAgenzia(java.lang.String,java.lang.String)' threw an unexpected exception: com.google.gwt.user.client.rpc.InvocationException: Error while loading serialization policy 4B8D0D03E16542B6163548C2B2ACD7CA
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:389)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:579)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.user.client.rpc.InvocationException: Error while loading serialization policy 4B8D0D03E16542B6163548C2B2ACD7CA
at com.gdevelop.gwt.syncrpc.RemoteServiceSyncProxy.<init>(RemoteServiceSyncProxy.java:89)
at com.gdevelop.gwt.syncrpc.RemoteServiceInvocationHandler.invoke(RemoteServiceInvocationHandler.java:99)
at com.sun.proxy.$Proxy0.CheckAuto(Unknown Source)
at it.ronf.server.RonfServiceImpl.checkCarAgenzia(RonfServiceImpl.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
... 21 more
Caused by: java.lang.NullPointerException: inputStream
at com.google.gwt.user.server.rpc.SerializationPolicyLoader.loadFromStream(SerializationPolicyLoader.java:110)
at com.gdevelop.gwt.syncrpc.RemoteServiceSyncProxy.<init>(RemoteServiceSyncProxy.java:87)
... 29 more
This is how I call the server to server function on the client side:
btnVerificaDisponibilit.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event){
RonfService.checkCarAgenzia("b","Mini", new AsyncCallback<Integer>(){
#Override
public void onFailure(Throwable caught){
}
#Override
public void onSuccess(Integer result){
if(result > 1){
btnAvviaTrasferimento.setVisible(true);
System.out.println("c'รจ");
}
else errorLabel.setText("Non ci sono modelli disponibile in altre agenzie.");
}
});
}
});
And this is the function on my server side:
#Override
public int checkCarAgenzia(String agenzia, String tipologia){
int n = 0;
if(agenzia.compareTo("b")==0){
final RonfService rpcService = (RonfService) SyncProxy.newProxyInstance(RonfService.class,"http://localhost:8081/Ronf-project/ronf/", "ronfservice");
n = rpcService.CheckAuto(tipologia);
}
else if(agenzia.compareTo("a")==0){
final RonfService rpcService = (RonfService) SyncProxy.newProxyInstance(RonfService.class, "http://localhost:8082/Ronf-project/ronf", "ronfservice");
n = rpcService.CheckAuto(tipologia);
}
return n;
}
#Override
public int CheckAuto(String tipologia){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<Auto> auto = new ArrayList<Auto>(session.createQuery("from Auto where Tipologia ='" + tipologia + "' and Disponibilita='true'").list());
session.getTransaction().commit();
return auto.size();
}
Why does the serialization problem appear only when I try to communicate with server B but not when I try to communicate with server A?
ps: this is my rpc.gwt file
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException, true, true, true, true, com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException/3936916533, 3936916533
com.google.gwt.user.client.rpc.RpcTokenException, true, true, false, false, com.google.gwt.user.client.rpc.RpcTokenException/2345075298, 2345075298
com.google.gwt.user.client.rpc.XsrfToken, false, false, true, true, com.google.gwt.user.client.rpc.XsrfToken/4254043109, 4254043109
it.ronf.client.RonfService, false, false, false, false, _, 1028614166
it.ronf.client.dto.AccountDTO, true, true, true, true, it.ronf.client.dto.AccountDTO/2817033572, 2817033572
it.ronf.client.dto.AgenziaDTO, true, true, true, true, it.ronf.client.dto.AgenziaDTO/2138136895, 2138136895
[Lit.ronf.client.dto.AgenziaDTO;, true, true, false, false, [Lit.ronf.client.dto.AgenziaDTO;/2014206060, 2014206060
it.ronf.client.dto.AutoDTO, true, true, true, true, it.ronf.client.dto.AutoDTO/3433806794, 3433806794
[Lit.ronf.client.dto.AutoDTO;, true, true, false, false, [Lit.ronf.client.dto.AutoDTO;/1522893402, 1522893402
it.ronf.client.dto.ClienteDTO, true, true, true, true, it.ronf.client.dto.ClienteDTO/2249269015, 2249269015
it.ronf.client.dto.NoleggioDTO, true, true, true, true, it.ronf.client.dto.NoleggioDTO/2812187262, 2812187262
[Lit.ronf.client.dto.NoleggioDTO;, true, true, false, false, [Lit.ronf.client.dto.NoleggioDTO;/1459858797, 1459858797
it.ronf.client.dto.RichiestaRifornimentoDTO, true, true, true, true, it.ronf.client.dto.RichiestaRifornimentoDTO/413727488, 413727488
[Lit.ronf.client.dto.RichiestaRifornimentoDTO;, true, true, false, false, [Lit.ronf.client.dto.RichiestaRifornimentoDTO;/793440202, 793440202
it.ronf.client.dto.RichiestaTrasferimentoDTO, true, true, true, true, it.ronf.client.dto.RichiestaTrasferimentoDTO/3484920730, 3484920730
[Lit.ronf.client.dto.RichiestaTrasferimentoDTO;, true, true, false, false, [Lit.ronf.client.dto.RichiestaTrasferimentoDTO;/1065675269, 1065675269
java.lang.Exception, true, false, true, false, java.lang.Exception/1920171873, 1920171873
java.lang.Long, true, true, true, true, java.lang.Long/4227064769, 4227064769
java.lang.Number, true, false, true, false, java.lang.Number/300033342, 300033342
java.lang.RuntimeException, true, false, true, false, java.lang.RuntimeException/515124647, 515124647
java.lang.String, true, true, true, true, java.lang.String/2004016611, 2004016611
java.lang.Throwable, true, false, true, false, java.lang.Throwable/2953622131, 2953622131
java.util.ArrayList, true, true, false, false, java.util.ArrayList/4159755760, 4159755760
java.util.Arrays$ArrayList, true, true, false, false, java.util.Arrays$ArrayList/2507071751, 2507071751
java.util.Collections$EmptyList, true, true, false, false, java.util.Collections$EmptyList/4157118744, 4157118744
java.util.Collections$SingletonList, true, true, false, false, java.util.Collections$SingletonList/1586180994, 1586180994
java.util.LinkedList, true, true, false, false, java.util.LinkedList/3953877921, 3953877921
java.util.Stack, true, true, false, false, java.util.Stack/1346942793, 1346942793
java.util.Vector, true, true, false, false, java.util.Vector/3057315478, 3057315478