How to tag a particular version in jackrabbit / JCR? - versioning

I want to know if I can tag a particular version.
I want to use JCR in my project and we have many hierarchical type tree made of different type of nodes and we need to save a version after bunch of changes for staging or production. I want to know how can I tag the particular version so that all the changes made for particular node and its children will be saved.
Thanks!!!

Yes, you can tag the versions in a version history with strings of your choosing. But JCR 2.0 calls them "labels".
First, you need to find the VersionHistory for a particular node that's been checked in:
String path = ... // the path to the versioned node
VersionManager versionManager = session.getWorkspace().getVersionManager();
VersionHistory history = versionManager.getVersionHistory(path);
Then you can find the specific Version that you want to label, either by iterating over all the versions, by getting the "root version", or getting the base version. I won't show this since there's so many ways to do this.
// Find the version ...
Version versionToBeLabeled = ...
Then you can add a label to this version. Note that a label can only be used once within the version history of a single node, so when adding a label you can choose whether to move an existing label (if there is one) or throw an exception. Here's code that moves it if it already is used:
// Add a user-defined label to this version ...
String versionName = versionToBeLabeled.getName();
String versionLabel = "MyLabel";
boolean moveLabel = true;
VersionHistory.addVersionLabel(versionName, versionLabel, moveLabel);
Note that the version names are determined by the JCR implementation, whereas labels are user-defined. This is why it's often very convenient to add your own labels and then find particular Version instances by label rather than by some implementation-determined name:
Version foundVersion = versionHistory.getVersionByLabel(versionLabel);
And of course you can find out whether there's any Version in the history with a particular label:
if ( versionHistory.hasVersionLabel(versionLabel) ) {
// do something
}
or if a specific version has a label:
Version version = ...
if ( versionHistory.hasVersionLabel(version,versionLabel) {
// do something
}
and even remove a particular label:
versionHistory.removeLabel(versionLabel);
For more information, see Section 15.4 of the JCR 2.0 (JSR-283) specification.

Related

Getting item from database returns only en version

I'm trying to get an item from database then publish it via code. The item only has pt-pt language (portugal)
I'm using Database.GetDatabase, when I try to get the item from the database. It gives me an item that has en language.
Item item = Database.GetDatabase("master").GetItem(guid);
Then when I try to edit the item using Editing.BeginEdit(), it edits the en version then proceeds to publish it.
Is there a way to get the pt-PT version then edit that version instead of en?
Each item can contain multiple languages. You can use the Sitecore.Globalization.Language class to specify a language when accessing an item using the Sitecore.Data.Database.GetItem() method. For example, to access the current version of the /Sitecore/Content/Home item in the default en language:
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Globalization.Language language = Sitecore.Globalization.Language.Parse("en");
Sitecore.Data.Items.Item home = master.GetItem("/sitecore/content/home",language);
Note
If you do not specify a language, Sitecore uses the context language by default. Sitecore user interface components specify the content language.
You can use the Sitecore.Data.Items.Item.Versions.Count property to determine if any versions exist for a language. For example, to access the current version in each language of the /Sitecore/Content/Home item in the Master database:
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.Item home = master.GetItem("/sitecore/content/home");
foreach (Sitecore.Globalization.Language language in home.Languages)
{
Sitecore.Data.Items.Item langItem = home.Database.GetItem(home.ID, language);
if (langItem.Versions.Count > 0)
{
// Process language item
}
}

Maximum call stack size exceeded when using the new typescript enabled version of reactjs

I use the new typescript supported version of reactjs
along with the redux-orm and when u try to insert a value into the store i get this issue of "Maximum call stack size exceeded" the same works with the old template
Below is the code with new typescript supported reactjs which throws the error
https://reactjs.org/docs/static-type-checking.html#typescript and the old github version https://github.com/microsoft/TypeScript-React-Starter which works.
https://drive.google.com/open?id=15eolNjeYroyubgSmbGaaKfjxbe-IZ8KK
I am unable to understand what is different that causes the error with the new version. Thanks for any help.
Properties can't be defined directly on Model classes.
The root cause lies in the create-react-app's babel preset - transpilation output introduces additional property descriptors in Model prototype chain.
These properties interfere with descriptors installed by redux-orm during schema registration, resulting in Maximum call stack size exceeded error.
This can be avoided through declaration merging, specifically by providing a class and an interface with matching names. The interface contains Model properties, the class is almost 1:1 to JS Model definition.
Example:
interface Book {
id: number
title: string
}
class Book extends Model<typeof Book> {
static modelName = 'Book' as const
static fields = {
id: attr(),
title: attr()
}
}
I've created a repo with working example: https://github.com/tomasz-zablocki/redux-orm-ex-types-react-example
Mind you, these are custom types, but it's definitely where I'd like to take the #types/redux-orm package to, likely with the 0.14 release of redux-orm.

Can you alter a Custom Attribute's enum list in Maya?

I'm adding a custom attribute that is an enum list to some of my nodes. I can easily do this with addAttr. But I don't see a way to later add a new enum value or change the enum list. Is that possible?
I have found a way to do this but it seems there should be an easier way. For my workaround, if the attribute exists I grab its value and delete the attribute. Then I add the revised attribute back into the node and set its value to the old value. By changing $enumValues I can edit the list of enums. (Note I only plan to add values not delete values) This script demonstrates my workaround:
string $attrName = "MaterialType";
string $enumValues = "Water:Sky:Terrain:Building:Road:";
string $selected[] = `ls -sl`;
if(`size $selected` == 1)
{
string $attrFullName = $selected[0]+"."+$attrName;
$existingValue = 0;
if(attributeExists($attrName, $selected[0]))
{
$existingValue = `getAttr $attrFullName`;
deleteAttr $attrFullName;
}
addAttr -ln $attrName -at "enum" -en $enumValues $selected;
setAttr $attrFullName $existingValue;
}
else
{
print "You must have 1 object and only 1 object selected\n";
};
Worth mentioning, if I run this script it does change the enum's values but these changes don't show up in Maya's interface until I close the file and reopen the file.
Any suggestions on how to do this more gracefully would be appreciated.
I might be a bit late, but you can use the "-edit" flag in addAttr.
addAttr -edit -enumNames "A:B:C" "node.enumAttrName"
However, you still need to refresh manually or with refreshEditorTemplates
Edit:
You might also want to consider optionMenuGrp. You can add menuItems via the -parent flag. You can remove a specific child with the deleteUI command or remove all children with the -deleteAllItems flag in edit mode on the optionsMenuGrp.
What you're doing - deleting the attribute and re-adding -- is unfortunately the only way to do this. Maya enums are pretty lame.
The attribute should be working correctly after the script is done - you may need to deselect and reselect it to properly refresh the attribute editor. You can check it with an listAttr -ud on your object after the script runs - you should see your attribute name in the results, even if the UI has not refreshed.

Indexing PDF documents with addtional search fields using SolrNet?

I found this article useful when indexing documents, however, how can I attach additional fields so I can pass in, say, the ID of the document in our database for use in displaying the search results? I thought by using the Fields (Of the ExtractParameters class) property I could index additional data with the document, but that doesn't seem to work or that is not its function.
Example code:
var solr = ObjectLocator.Instance.Resolve<ISolrOperations<IndexDocument>>();
var guid = Guid.NewGuid().ToString();
using (var fileStream = System.IO.File.OpenRead(Server.MapPath("~/files/") + "greenroof.pdf"))
{
var response =
solr.Extract(
new ExtractParameters(fileStream, "greenRoof1234")
{
ExtractFormat = ExtractFormat.Text,
ExtractOnly = false,
Fields = new[] { new ExtractField("field1", "value1"), new ExtractField("field2", "value2") }
});
}
#aitchnyu is correct, passing the values via the literal.field=value method is the correct way to do this.
However, according to this post on ExtractingRequestHandler support in the SolrNet Google Group, there was a bug with the ExtractParameters.Fields not working properly. This was fixed in the 0.4.0.X versions of SolrNet. Please make sure you are using one of the latest versions of SolrNet. You can obtain that by one of the following means:
Project Site Downloads
NuGet PreRelease Package
Also that discussion has some good examples of using the ExtractingRequestHandler in SolrNet as well as a workaround for adding the additional field values if you cannot upgrade to a newer version of SolrNet.
This is sufficient: http://wiki.apache.org/solr/ExtractingRequestHandler#Literals .
In general use a literal.field=value while uploading.
It turned out not to be an issue with SOLRNet, but my knowledge of SOLR, in general. I needed to specify the fields in my schema. After i added the fields to my schema they were visible in my SOLR query.

JDO for GAE: Update objects returned by a query

There is persistable class Project, each instance of which has list of objects of Version type (owned one-to-many relation between Project and Version classes).
I'm getting several Version objects from datastore with query, change them and try to save:
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query q = pm.newQuery(Version.class, "... filters here ...");
q.declareParameters(" ... parameters here ...");
List<Version> versions = (List<Version>)q.execute(... parameters here ...);
if (versions.size() > 0) {
for (Version version : versions) {
version.setOrder(... value here ...);
}
pm.makePersistentAll(versions);
}
tx.commit();
return newVersion.toVersionInfo();
} finally {
pm.close();
}
Everything is executed without errors, query actually returns several objects, properties are set correctly in runtime versions list, but objects properties are not updated in datastore.
Generally, as far as I understand, versions should be saved even without calling
pm.makePersistentAll(versions);
, since object properties are set before pm.close(), but nothing is saved, if this row is omitted, as well.
At the same time, if I retrieve instance of type Project (which owns many instances of type Version) with pm.getObjectById() method, and walk through all related Version objects in the loop, all changes are saved correctly (without calling pm.makePersistent() method).
The question is, what's wrong with such way of updating objects? Why Version object properties are not updated in datastore?
I could not find anything helpful neither in JDO nor in GAE documentation.
Thanks for advice about logs from DataNucleus and sympathy from Peter Recore :)
Frankly, I missed few important points in my question.
Actually,between
tx.begin();
and
Query q = pm.newQuery(Version.class, "... filters here ...");
I am retrieving Project instance, and after Version instances updating loop I am persisting some one more Version object.
So, I actually retrieved some of versions list twice, and according to committing order in logs, Project instance was saved twice, as well. The second save operation overwritten the first one.
I changed the order of operations, and got expected behavior.

Resources