Move fields from table to local table based on structure - dynamic-programming

I customized the table KNVV. The append structure includes a structure where I actually defined all my custom fields. Lets call it zz_knvv_app_s.
A function pool, used to get and set the custom fields, has a function called ZSD_FOO_GET_DATA. It is exporting structure es_knvv TYPE knvv.
My current solution works, but is kind of stupid:
FUNCTION ZSD_FOO_GET_DATA.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" EXPORTING
*" REFERENCE(ES_KNVV) TYPE KNVV
*"----------------------------------------------------------------------
es_knvv-zzfoo = knvv-zzfoo.
es_knvv-zzbar = knvv-zzbar.
es_knvv-zzbaz = knvv-zzbaz.
" there are actually many more fields...
ENDFUNCTION.
What I am looking for is something like that:
loop through KNVV
assign the custom fields that are defined in my dictionary structure zz_knvv_aps_s...
... from KNVV to ES_KNVV
something similary is also required for ZSD_FOO_GET_DATA
I am kind of new to ABAP. I think about looping and field symbols, but cant get it right. How would you solve it?

You could try to use a named include:
create a structure - let's say ZZ_MY_KNVV_FIELDS
KNVV has an append structure ZZ_KNVV_APP_S
ZZ_KNVV_APP_S has a single entry .INCLUDE ZZ_MY_KNVV_FIELDS with a group name ZZ_MY_FIELDS
same for any other output structure
You can then address all of your fields using KNVV-ZZ_MY_FIELDS as a structure of type ZZ_MY_KNVV_FIELDS

Related

I want to create azure function which requests data from request body using with block but how I can implement it in digital twins table

WITH will be used to define variables that can be used in the set functionality
WITH T.name, T.description
The Query will have to support the variables being defined, for example, if using a “SELECT * FROM DigitalTwins….” Where T is not declared, name and description should still exist as properties of the Twin. Use if declaring the Response set as T or other letters is usually done when performing joins. From a general perspective, the logic should be to validate that the variables declared exist as properties in the response elements, regardless of there being a T. or other letter in front. Split on . and take the last element for verification.
WITH T.name as name, C.description as description - Allow to cast variables to other names same as in the DT SELECT query.
Put it all together:
SELECT * FROM DIGITALTWINS T WHERE (IS_OF_MODEL('dtmi:com:adt:telemetry:pointIO;1') AND T.units='cubic_feet_per_minute') UPDATE WITH name, pointType SET T.displayName=name, T.brickTags=pointType
Above will update all twins returned in the query with two constant property values.

Arrays of composite types in PostgreSQL via NodeJS

I'm using Node.JS ("pg" package) to connect to a PostgreSQL database hosted on Heroku. I need to create a column in my table that will contain an array of different data types. By looking at other questions previously asked on Stackoverflow, I understand i can create composite data types that I can use to declare the array with. Like:
create type my_item as (
field_1 text,
field_2 text,
field_3 text,
field_4 number
);
However, I don't understand how to implement this when using Node.JS. Where do I put it in my files and at what point do I run it?
I have an index.JS file containing my Pool instance and the database access info. My functions are stored in a models folder. Each function has its own SqlString variable which is then passed to the query. Like:
export async function getScores() {
const data = await query(`SELECT * FROM score`);
return data.rows;
}
Appreciate any help.
There is no such thing as array of different composite types in Postgresql. You might need to store the column as json/jsonb type instead and deal with them at the application level. Or create a superset type of all possible types in the array and deal with NULLs at the application level. That only works if the subset types don't overlap different types on the same key.
Also the main usecase for composites is related to INSERT/UPDATE/DELETE queries, aka anything that requires value interpolation from the application. Of course it's no use in your example code.

AEM Query builder exclude a folder in search

I need to create a query where the params are like:
queryParams.put("path", "/content/myFolder");
queryParams.put("1_property", "myProperty");
queryParams.put("1_property.operation", "exists");
queryParams.put("p.limit", "-1");
But, I need to exclude a certain path inside this blanket folder , say: "/content/myFolder/wrongFolder" and search in all other folders (whose number keeps on varying)
Is there a way to do so ? I didn't find it exactly online.
I also tried the unequals operation as the parent path is being saved in a JCR property, but still no luck. I actually need unlike to avoid all occurrences of the path. But there is no such thing:
path=/main/path/to/search/in
group.1_property=cq:parentPath
group.1_property.operation=unequals
group.1_property.value=/path/to/be/avoided
group.2_property=myProperty
group.2_property.operation=exists
group.p.or=true
p.limit=-1
This is an old question but the reason you got more results later lies in the way in which you have constructed your query. The correct way to write a query like this would be something like:
path=/main/path/where
property=myProperty
property.operation=exists
property.value=true
group.p.or=true
group.p.not=true
group.1_path=/main/path/where/first/you/donot/want/to/search
group.2_path=/main/path/where/second/you/donot/want/to/search
p.limit=-1
A couple of notes: your group.p.or in your last comment would have applied to all of your groups because they weren't delineated by a group number. If you want an OR to be applied to a specific group (but not all groups), you would use:
path=/main/path/where
group.1_property=myProperty
group.1_property.operation=exists
group.1_property.value=true
2_group.p.or=true
2_group.p.not=true
2_group.3_path=/main/path/where/first/you/donot/want/to/search
2_group.4_path=/main/path/where/second/you/donot/want/to/search
Also, the numbers themselves don't matter - they don't have to be sequential, as long as property predicate numbers aren't reused, which will cause an exception to be thrown when the QB tries to parse it. But for readability and general convention, they're usually presented that way.
I presume that your example was just thrown together for this question, but obviously your "do not search" paths would have to be children of the main path you want to search or including them in the query would be superfluous, the query would not be searching them anyway otherwise.
AEM Query Builder Documentation for 6.3
Hope this helps someone in the future.
Using QueryBuilder you can execute:
map.put("group.p.not",true)
map.put("group.1_path","/first/path/where/you/donot/want/to/search")
map.put("group.2_path","/second/path/where/you/donot/want/to/search")
Also I've checked PredicateGroup's class API and they provide a setNegated method. I've never used it myself, but I think you can negate a group and combine it into a common predicate with the path you are searching on like:
final PredicateGroup doNotSearchGroup = new PredicateGroup();
doNotSearchGroup.setNegated(true);
doNotSearchGroup.add(new Predicate("path").set("path", "/path/where/you/donot/want/to/search"));
final PredicateGroup combinedPredicate = new PredicateGroup();
combinedPredicate.add(new Predicate("path").set("path", "/path/where/you/want/to/search"));
combinedPredicate.add(doNotSearchGroup);
final Query query = queryBuilder.createQuery(combinedPredicate);
Here is the query to specify operator on given specific group id.
path=/content/course/
type=cq:Page
p.limit=-1
1_property=jcr:content/event
group.1_group.1_group.daterange.lowerBound=2019-12-26T13:39:19.358Z
group.1_group.1_group.daterange.property=jcr:content/xyz
group.1_group.2_group.daterange.upperBound=2019-12-26T13:39:19.358Z
group.1_group.2_group.daterange.property=jcr:content/abc
group.1_group.3_group.relativedaterange.property=jcr:content/courseStartDate
group.1_group.3_group.relativedaterange.lowerBound=0
group.1_group.2_group.p.not=true
group.1_group.1_group.p.not=true

Codeigniter routing URL with product name to product id

I need to redirect the URLs like this http://mysite.com/store/store-name to http://mysite.com/stores/products/store-id. Note that i need to get the store id from the database. So is it possible to do db operations in routes.php?
And in documentation the syntax is give as $route['store/:any']. How to get the value of second parameter here which is mentioned as :any.
There's not really any good nor simple way of running database queries through the routes. You can however have in the beginning of the controller function a validation.
I asume your store-name is some sort of slug for the product? Basicly you can validate if value is numeric or not, and if not find by slug and then redirect.
config/routes.php
$route["store/(.*)"] = 'stores/products/$1';
/* () and $1 together passes the values */
controllers/stores.php
/* Class etc. */
function products($mix) {
if (is_numeric($mix))
$int_id = $mix;
else {
$row = $this->get_where('products', array('slug' => $mix))->row();
$this->load->helper('url');
redirect("stores/products/{$row->id}");
}
/* Do stuff with the $int_id */
}
This asumes that you have:
A table named products
A column named id that's your products id
A column named slug that that's based on your store-name
I may be a little late to the party, but I may have an alternative suggestion.
I use the following for my routes:
http://mysite.com/store/1/store-name
Reason being... Based on your method, if you create
http://mysite.com/store/store-name
but then after a period of time (of which no doubt Google has indexed your page) you decide for what ever reason you have to change the name of the store to "Wonderful store name", you would naturally change your link to
http://mysite.com/store/wonderful-store-name
Which kills your SEO and any index links.
My solution of using http://mysite.com/store/1/store-name means that you can change store-name to anything you want, but it will always reference 1 meaning the user will still see the related page.
Anything is possible with CodeIgniter routes. Its all in the way you code it. Routing in CI is really flexible. You can use regular expressions besides the standard CI wildcards (:any)(:num). You can even add prefixes or suffixes to the path variables if you have to like:
$route['store/(:any)'] = "redircontroller/redirfunction/$1";
// for instance the namelookup method of the mystores controller
$route['stores/products/(:any)'] = "mystores/namelookup/$1";
You get the second parameter(and third and so on) by defining the variables in your route value which get passed to the controller method you define. If 'products' in you new url is also a variant you should start your wildcard expression there instead. You could also pull parameters out of the url using the URI class ($this->uri->segment(n)).
You don't, however, do database operations in routes.php. You do your database operations in the controller where you route to. My guess is that you'll have to match the store id using whatever is used in the url in a query.
In any case the path that you are using the routes file for is the path the user will see. To do the redirect you have to accept the original path and then redirect the user to the new path like so:
// in some controller that's attached to the original url
public function redirfunct($var){
$this->load->helper('url');
redirect(base_url('stores/products/' . $var));
}
I hope this helps you.
Yes that is easy, you only need to show the ID instead of the name,
you must be doing like storeName> Click to view details
Make it as
storeId> Click to view details
and when you are passing the parameter to the database, change the check of mysql, change it to id instead of name , that can be some like
" select yourRequiredColumn from table_name where id=".parameter."
Thanks

NAnt: task that returns/set a collection of objects?

I'd like to augment NAntContrib's set of Perforce tasks by adding the p4 labels task.
The p4labels task would have to return a collection of labels, or even ideally, a collection of label info: name, date/time, description.
Looking into NAntContrib's code for other call (p4info for example), it looks like it's rather easy to return simple strings from a task, but I've not managed to find a way to return a collection of labels. A potential use would be to later pass this collection to a function to get the latest label in the collection or to a foreach task to iterate over to deal with each within the collection, for example.
Is this even possible in NAnt? From all I've seen, it seems you can declare sets and collections, but not return them from a task or a function.
For the record, I've declared a LabelInfo NAnt type as well as a LabelInfoCollection, but really I don't know how I would return one from a task.
Any tips are welcome.
Looking at NAntContrib's sql task's strategy to deal with returning a set of values, it seems a solution would be to store the data in a file and pass that file to whatever function or task requiring the data.
It'd then possible to pass this to file to a foreach task that can iterate over the lines in the file. Data stored in CSV format is very easy to parse:
<p4labels user="bob" filter="*VerifiedBuild*" max=100 output="myfile.csv" />
<foreach item="Line" in="myfile.csv" delim="," property="label,date,comment">
<echo message="Label: ${label} Created on: ${date} - ${comment}" />
</foreach>

Resources