How do I create a new field type plugin in Solr from an existing one? - solr

So I created a "UnitField" in solr that works like CurrencyField with a few changes. Therefore I basically just copy-and-pasted the code form CurrencyField (first I tried extending, but of no avail) and adjusted it.
Now the problem is: I want it to be a standalone JAR and in its own package. But unfortunately some methods from FieldType and SchemaField classes are only declared as default (package scope) and therefore are not visible in my context. Also copying them is not really a solution, as that would result in more code not being visible ...
The Solr wiki says one can implement custom field types. Is there any way to solve this?

You can maintain the same package as the one used by the CurrencyField field that would allow you the access the default methods.
You can still package these classes into a separate jar and add it to the Solr core lib folder so that it is available for the programs.

Related

Environment variable as custom metadata type in Salesforce

I am trying to represent environment variables in the Salesforce codebase and came across Custom Metadata Types. So based on which Sandbox I am in, I want to vary the baseURL of an external service that I am hitting from my apex class. I want to avoid hard coding anything in the class, and hence trying to find out an environment variable like solution.
How would you represent the URL as a custom metadata type? Also, how can I access it in the class? What happens when a qa sandbox is refreshed from prod? Do they custom metadata type records get overridden?
How are you calling that external service? If it's truly a base url you might be better of using "named credential" for it. It'll abstract the base url away for you, include authentication or certificate if you have to present any...
Failing that - custom metadata might be a poor choice. They're kind of dictionary objects, you can add more (but not from apex) but if you deploy stuff using Git/Ant/SFDX CLI rather than changesets it'd become bit pain, you'd need different custom metadata value for sandbox vs prod. Kinda defeats the purpose.
You might be better off using custom setting instead (hierarchy is enabled by default, list you'd have to flip a checkbox in setup. List is useful if you need key-value kind of pairs, similar to custom metadata): https://salesforce.stackexchange.com/questions/74049/what-is-the-difference-between-custom-settings-and-custom-metadata-types
And you can modify them with Apex too. Which means that in ideal world you could have a "postcopy" class running as soon as sandbox is refreshed that overwrites the custom setting with the non-prod value. For named credential I don't think you can pull it off, you'd need a mini deployment that changes it or manual step (have you seen https://salesforce.stackexchange.com/q/955/799 ?)

Solr runtimelib usage

I am trying to use the support that was added for specifying jars as runtime libraries when creating request handler's and other components. However, it is not clear to me from the documentation (https://cwiki.apache.org/confluence/display/solr/Adding+Custom+Plugins+in+SolrCloud+Mode) whether this only works through components created through the ConfigAPI or if it should also work if runtimeLib="true" is added to solrconfig.xml.
For example:
<requestHandler name="/browse" class="solr.SearchHandler" runtimeLib="true">
I added runtimeLib="true" to all of my searchComponents and requestHandlers in solrconfig.xml to see if it would work, but when starting the Solr instances, they all fail because they are looking for a class that is in a custom jar file. I've added the .system collection and uploaded the jars per the Solr Reference Guide/Wiki documentation and can see the .system collection and I can also see that my collection's configoverlay.json has the two jars I uploaded.
My collection's configoverlay.json contents
{"runtimeLib":{
"my-custom-jar":{
"name":"my-custom-jar",
"version":1},
"sqljdbc41-jar":{
"name":"sqljdbc41-jar",
"version":1}}}
Is specifying a runtimeLib attribute in solrconfig.xml supported? If so, what is the proper usage?
You're almost there. Further down on the page that you are linking to there is an example of creating a parser. The example uses completely different example values than the rest of the page, so I can understand why you may have glossed over it.
The point is, that you need to register your request handler using the curl command provided on the page. Unfortunately, you need to use a command that I had to dig into the source code to find: create-requesthandler. To create a request handler using your values above, I think you should issue the command
curl "http://{servername}:8983/solr/{collection}/config" -H 'Content-type:application/json' -d '{
"create-requesthandler": {
"name":"my-custom-jar",
"runtimeLib": true,
"class": "solr.SearchHandler"
}
}'
remember to replace the values of servername and collection. And change the port if you are using a non-default value.
Restart your solr server and the plugin should be available.
Sadly loading classes from plugins in managed schemas seems to be unsupported at the moment:
https://issues.apache.org/jira/browse/SOLR-8751
This probably means that you have to add it dynamically via the API as mentioned above. So the solution could be to use a minimal managed schema and add the fields requiring external jars afterwards.
For me, the simplest solution was not to use the Blob API at all, and directly add the required jars to the classpath of the Solr instance, as described here:
http://lucene.472066.n3.nabble.com/Problems-while-setting-classpath-while-upgrading-to-Solr-5-1-from-Solr-4-X-tp4209853p4209863.html

loadmodel taking plugin model

I have a plugin with a model called profile. Also I have a profile model in app/model folder, which contains a function getProfileDetails. This function I am calling from the AppController, using the following code
function beforeRender(){if ($this->isAuthorized())
{
$this->loadModel('Profile');
$this->set('ownProfile', $this->Profile->getProfileDetails($this->Auth->user('id')));
}
}
Whenver I access the plugin through the url, Im getting getting the following error
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'getProfileDetails' at line 1
/lib/Cake/Model/Datasource/DboSource.php(436): PDOStatement->execute(Array)
/lib/Cake/Model/Datasource/DboSource.php(403): DboSource->_execute('getProfileDetai...', Array)
If I give the same function in Plugin/model/profile, everything is working. How to tell cake to take the App/model/profile model in loadmodel ?
Cake 2.0 and previous versions do not support duplicate Model/Controller names. The fact that such a setup was working in 1.3 and lower was an unintended side-effect unknown to the developers. Cake loads all the classes, from plugins and the actual application. So a duplicate classname anywhere in you application is bound to mess things up.
Support for duplicate classnames will likely be added in Cake 3.0 as this version willy rely on PHP 5.3 which, in turn, has support for namespaces needed to implement the ability to create duplicate classnames.
The only workaround I know of is renaming your plugin's controllers, models and views, by prefixing the plugin name to the files and classnames, for example. If the plugin uses the same database tables as the application you'll have to use the $useTable model attribute to point the renamed models to the right database tables.
Some background is covered in this bug report.

Renaming CoreData classes while allowing App updates

I have made the mistake when starting the coding an iPhone App of not adding a prefix to my classnames, and as such have a conflict (A CoreData class called Category). The project build fine until the recent update of Xcode, and only now I realize the mistake.
Is it possible to rename CoreData classes while keeping a working system after update?
If I add a new version to the Datamodel and rename the class, the App updates, but it seems that the old table is deleted and a new (empty) one created. Obviously all the links subsequently are broken. I would like to maintain the data while making the change.
In Java EE you can overrule the table name if I remember correctly, and as such I could stick to the old class name to name the table. Is there any such possibility with CoreData?
Thanks in advance! I have to find a way to update the DB without all the Apps out in the field breaking.
Actually, it i documented quite well by Apple:
If you rename an entity or property,
you can set the renaming identifier in
the destination model to the name of
the corresponding property or entity
in the source model. You typically set
the renaming identifier using the
Xcode Data Modeling tool, (for either
an NSEntityDescription or an
NSPropertyDescription object). In
Xcode, the renaming identifier is in
the User Info pane of the Detail Pane,
below the version hash modifier (see
The Browser View in Xcode Tools for
Core Data). (Mac OS X Developer Library )
But actually for me it seems to work just to change the Classname and leave the rest of the model alone.

how to include XSD schema files in Silverlight library?

Within a Silverlight library, I need to validate incoming XML against a schema. The schema is composed of 5 interdependent .xsd files; the main file uses "xs:import" to reference all of the others, and there are other references among them.
Assuming that the .xsd files need to be distributed with the library (i.e. not hosted on some well-known external URL), how should I structure my project to include them?
I have found that I can embed them in the library project with build type "Resource" and then load them (individually) using Application.GetResourceStream() and a relative URI with the ";content" flag in it. But if I take this approach, can I validate against the interdependent set of 5 files? What happens when the schema parser tries to resolve the interdependencies?
Or should I embed them with build type "Content" and access the main one with some other sort of URL?
Or???
To summarize: how should I use these 5 .xsd files in my project so that I will be able to validate XML against them?
EDIT: It's not clear whether it's even possible to validate in Silverlight. I spun off a related question.
I cannot say much about Silverlight limitations with respect to validation, but the question itself is more generic - one might want to store .xsd files as resources in a desktop .NET application, for example - so I will answer that part.
You can have full control over resolution of URIs in xs:import by means of XmlSchemaSet.XmlResolver property. Just create your own subclass of XmlResolver, override GetEntity() method, and implement it using GetResourceStream(), or GetManifestResourceStream(), or whichever other way you prefer.

Resources