REST avoid duplication of efforts - rest

Consider the example scheme below, as you can see a Regiment has a many-to-many relationship with contractors which can be the same for several regiments.
If I have to create two regiments with several hundreds of common contractors I will basically upload two times the same contractors to the server:
<regiments>
<regiment>
<contractors>
<conctractor>
<id>1</id>
...
</contractor>
<conctractor>
<id>2</id>
...
</contractor>
</contractors>
</regiment>
<regiment>
<contractors>
<conctractor>
<id>2</id>
...
</contractor>
<conctractor>
<id>5</id>
...
</contractor>
</contractors>
</regiment>
</regiments>
I am using a PUT where regiments and contractors have a predefined ID because I'm using REST to synchronize a desktop application to a web application and both have to use the same IDs for their entities.
Notice the contractor object is very big and has sublists of its own so re-uploading even a single contractor is a big loss of time and resources for the server.
How can I avoid uploading the same contractors over and over?

There is no reason you can't use a representation that allows you to link to an existing Contractor which has previously been PUT:
<regiments>
<regiment>
<contractors>
<contractor-ref uri="/contractors/1"/>
<contractor-ref uri="/contractors/2"/>
</contractors>
</regiment>
<regiment>
<contractors>
<contractor-ref uri="/contractors/2"/>
<contractor-ref uri="/contractors/5"/>
</contractors>
</regiment>
</regiments>

Related

VS Code Regex search to remove references based on containing text in string

I am attempting to remove all references of a managed package that is going to be uninstalled that spans throughout code base in VS Code
I have using a query to find the field permissions but am wondering if there is a way to search for the reference outside of specifying the exact field name compared to the field containing only "agf" since they are all using it.
Below is the search query:
<fieldPermissions>
<editable>false</editable>
<field>User.agf_Certified_Product_Owner__c</field>
<readable>false</readable>
</fieldPermissions>
In the field, I want to be able to find and delete the 5 associated lines from multiple files if they match "agf" in any combination. Something like the below:
<fieldPermissions>
<editable>false</editable>
<field>agf</field>
<readable>false</readable>
</fieldPermissions>
With any combination of agf in the field, delete all from any file it appears in.
Not an answer but too long for a comment
You don't have to? Profiles/perm sets don't block package's delete. Probably neither do reports.
You'd use your time better by searching for all instances of agf__ (that's with double underscore), should find fields, objects... used in classes, flows, page layouts etc. And search for agf. (with dot) should find all instances where your Apex code calls their classes marked as global.
Alternatively Apex / VF pages with dependencies on package will have it listed in their "meta.xml", for example
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<packageVersions>
<majorNumber>236</majorNumber>
<minorNumber>1</minorNumber>
<namespace>SBQQ</namespace>
</packageVersions>
<status>Active</status>
</ApexClass>
Last but not least - why not just spawn a dev sandbox and attempt the delete there? If it succeeds - great. If not - it'll list the dependencies that blocked the delete. It'll be "the real thing", it'll smite you even if your VSCode project doesn't contain all flows, layouts and thus could lull you into false sense of security. I'd seriously do it in sandbox and then run all tests for good measure, just in case there are some dynamic soql queries that don't count as hard, delete-blocking references.
After delete's done - fetch Profiles / Permsets from this org and the field references will be gone from the xml.

Load Site Specific Dictionary

We have dictionary under /content/dam for languages say (en-us, es-us) . When we load the page its injected and we have the translated content render on the page. As part of the requirement I have some doubts to clarify.
When I load the page, I see multiple calls of /libs/cq/i18n/dict.xxx.json, how can we restrict default dictionary calls?
/libs/cq/i18n/dict.en.json
/libs/cq/i18n/dict.en-US.json (We need only this one)
/libs/cq/i18n/dict.en.json
My custom dictionary /libs/cq/i18n/dict.en-US.json has only 5 labels, but in response i see via <%= slingRequest.getResourceBundle(slingRequest.getLocale()).keySet()%><br> , numbers of other labels may be injected via /libs/cq/i18n/dict.en.json
Is there way to load /libs/cq/i18n/dict.en-US.json as per site level. Say, I want to load the dictionary on /content/mySiteA/en-US and not on /content/mySiteB/en-US ? keeping in consideration that codebase is same.

Populating opcua address space with Nodes from an xml schema

Am working on a project to build an opc ua server from specification,
I've gone far enough on the implementation, am currently working on the write request, I already have a few nodes in the server address space.
There seem to be so many nodes, so many actually. It's almost impossible to create
and add the Nodes one by one.
Anyways back to the question, I've downloaded an xml file from opc foundation containing schema for all the nodes in the address space, Here is a link to the xml file
What is the most efficient way to create nodes from the xml file ? I am writing on a c95 compiler.
Below is a quick view of how Nodes are represented in the nodeset Xml file,
<Nodes>
<Node i:type="DataTypeNode">
<NodeId>
<Identifier>i=1</Identifier>
</NodeId>
<NodeClass>DataType_64</NodeClass>
<BrowseName>
<NamespaceIndex>0</NamespaceIndex>
<Name>Boolean</Name>
</BrowseName>
<DisplayName>
<Locale></Locale>
<Text>Boolean</Text>
</DisplayName>
<Description>
<Locale></Locale>
<Text>Describes a value that is either TRUE or FALSE.</Text>
</Description>
<WriteMask>0</WriteMask>
<UserWriteMask>0</UserWriteMask>
<RolePermissions />
<UserRolePermissions />
<AccessRestrictions>0</AccessRestrictions>
<References>
<ReferenceNode>
<ReferenceTypeId>
<Identifier>i=45</Identifier>
</ReferenceTypeId>
<IsInverse>true</IsInverse>
<TargetId>
<Identifier>i=24</Identifier>
</TargetId>
</ReferenceNode>
</References>
<IsAbstract>false</IsAbstract>
<DataTypeDefinition i:nil="true" />
</Node>
Programatically filling a running OPC-UA server with nodes is unacceptably slow.
you may want to investigate the ModelCompiler.
I found it fairly straightforward to fill a modeldesign XML with data and generate code and NodeSet2.xml. So even if you have no need for the generated C# code, which I suspect to be your case, this approach may be useful.
You may also want to look at the UA-.NETStandard repository.
It offers a method LoadFromXML method that reads your nodeset pretty quickly. You may find inspiration in this method.
Bon courage et un grand merci pour vos contributions au monde OPC-UA.
Maybe I'm a bit late, but I answer if it can help someone.
If you are using C/C++ with open62541 SDK I found that it is possible to generate *.c and *.h files to include in your opcua server, as described with some examples here: you only need to run a python program, providing some parameters and the name of output files to be generated, then include these files in your opcua server.
Another way that I found is using UaModeler by Unified Automation, in that case you can generate source files to include in your project, drawing your information model in the program and exporting it to xml or source files.

Remote stream multiple files in SOLR

I want to use SOLR's remote-streaming facility to extract and index the content of files.
This works fine if I pass stream.file=xxx as a parameter to the http GET method.
However, I have a lot of these, and want to batch them up (i.e. not have to have a GET per file).
Is there a way I can do this in SOLR?
e.g. I'd like to be able to POST some xml like this:
<add>
<doc stream_file="filename">
<field name="id">123</field>
</doc>
<doc>...
This has been recently asked (and answered) in the solr-user mailing list.
I find that multiple ADDs are fast, so long as you only COMMIT the batch and don't try to COMMIT after every ADD. I would guess that the performance penalty is not worth writing your own RequestHandler.

Storing templates using dictionary in c#

I have to store some templates based on the statecode.I cannot store them in database. So i thought of creating a dictionary with statecode as key and list as value. I have chosen a list because i need a template line by line.So each string in list is a line. Is there any better way of dealing with this kind of situation. Please comment.
private static readonly Dictionary<string, List<string>> NotaryForStates = new Dictionary<string, List<string>>()
{
{"AR",new List<string> {"Per Steve Hollowell, ESQ from the Legal Division of the AR, SOS. Telephone number for the Legal Division of the SOS: (501)-682-3012. Arkansas Code 16-47-101.", "State of Arkansas", "County of <notary county>","On this day, <sign date> before me, <name of notary>, the undersigned notary, personally appeared, <name of signer> who acknowledged he/she is the <title of signer> of <name of company> and that he/she as such <title of signer>, being authorized so to do, executed the foregoing instrument for the purposes therein contained, by signing the name of the corporation by himself/herself as <title of signer>.","In witness whereof I hereunto set my hand and official seal.","______________________","Notary Public","<Notary name>","My Commission expires: <notary commission date>"}},
{"CA",new List<string>{"State of California","County of <Notary County>","On <sign date> before me, <Notary Name>, Notary Public, personally appeared <Signing Party Name>, who proved to me on the basis of satisfactory evidence to be the person(s) whose name is subscribed to the within instrument and acknowledged to me that he/she executed the same in his/her authorized capacity, and that by his/her signature on the instrument the person, or the entity upon behalf of which the person acted, executed the instrument.","I certify under PENALTY OF PERJURY under the laws of the State of California that the foregoing paragraph is true and correct.","WITNESS my hand and official seal.","______________________________","Notary Public: «NotaryName»","My Comm. Expires: «NotaryCommExp»"}},
{"FL",new List<string>{"State of Florida","County of <Notary County>","On <sign date> before me, the undersigned, a Notary Public, for said County and State, personally appeared <Signing Party Name>, personally known to me to be the person that executed the foregoing instrument and acknowledged that is a <signer title> of <name of company> and that he/she did execute the foregoing instrument. <Name of Signer> is personally known to me.","_____________________","Notary Public: «NotaryName»","My Comm. Expires: «NotaryCommExp»"}}
};
First alternative: You may use a simple string instead of a list and separate the individual lines with Environment.NewLine ("\n"). You can create such strings easily with a StringBuilder object and split it again (if you need to) with the string.Split() method. This is also (slightly) faster than the List<string> approach.
Second alternative: You may use files and store only the filename in your dictionary.
Whether or not one of the above options is a better alternative to your original approach, depends on the concrete project you're working on. All in all, the List<string> approach might well be ok...
HTH!
Another alternative is to use resource files (which are commonly used for localization). Resource files provide a location for storing text or other types of objects which can be used across a Web site, WPF or Windows Forms application, thus creating a central location for maintaining the text. Using resource files can also simplify maintenance of your application.