tag:help-archives.hannonhill.com,2010-02-09:/discussions/how-do-i/14998-unique-identifiers-in-data-definitionsCascade CMS: Discussion 2015-01-19T16:30:28Ztag:help-archives.hannonhill.com,2010-02-09:Comment/353042222014-11-17T16:19:00Z2014-11-17T16:19:00ZUnique Identifiers in Data Definitions<div><p>Hi Nick,</p>
<p>To confirm, are you publishing this event data to an XML or JSON
file that is then consumed by the devices? If so, what you can do
is tweak your Format to either use a one-up integer for each event,
or generate a unique number.</p>
<p>Alternatively, every asset within Cascade Server is given a
unique ID. You could tweak your implementation to use individual
pages or blocks for the events and use an Index Block to gather
their information. The Index Block would then include both the
asset's unique ID (as an <code>id</code> attribute) and the actual
event data.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/353042222014-11-17T16:33:40Z2014-11-17T16:33:40ZUnique Identifiers in Data Definitions<div><p>Thanks for the speedy reply Ryan.</p>
<p>To clarify, the event data is in an XML file that is then
formatted into card elements visible on the webpage. I thought
about using the Format to do the incremented integer or a generated
unique number, but will that change every time the page is
republished(and re-run through the formatter)? --I am unsure.</p>
<p>While it would be possible to do your second suggestion
involving asset ID's, my events are all part of a single block. So
I would need a unique ID for the sub-element instances within the
data-definition. So essentially, every time a user hits the [+], a
new unique ID is generated with the element.</p></div>Nick tag:help-archives.hannonhill.com,2010-02-09:Comment/353042222014-11-17T16:50:46Z2014-11-17T16:50:46ZUnique Identifiers in Data Definitions<div><p>Not a problem at all, Nick.</p>
<blockquote>
<p>I thought about using the Format to do the incremented integer
or a generated unique number, but will that change every time the
page is republished(and re-run through the formatter)? --I am
unsure.</p>
</blockquote>
<p>Correct, as the events change and/or things are re-ordered, the
one up numbers would change. My assumption is the events are
added/removed from this structured data block when they are
upcoming or no longer necessary. When you have a moment, can you
describe a bit more why you need the unique IDs? Is there some sort
of archival going on?</p>
<blockquote>
<p>While it would be possible to do your second suggestion
involving asset ID's, my events are all part of a single block. So
I would need a unique ID for the sub-element instances within the
data-definition. So essentially, every time a user hits the [+], a
new unique ID is generated with the element.</p>
</blockquote>
<p>If you already have a unique ID for each event, why would you
still need a unique ID for the data definition content? This
solution would involve the following setup:</p>
<ul>
<li>A folder(s) to contain the events</li>
<li>Each event would be a separate block or page that has the same
data definition you use now, minus the repeating group</li>
<li>A page that contains a single DEFAULT region which has a Format
and Index Block applied to it.
<ul>
<li>The Index Block will be indexing the folder containing the
events (or the event Content Type if you are using pages)</li>
<li>The Format would generate your XML structure that is consumed
by your webpage</li>
</ul>
</li>
</ul>
<p>So your users would simply create a new "event", or delete an
existing one, and the page that generates the XML would be
published, as opposed to continually adding/removing repeating
groups from a single page. This gives you the advantage of being
able to archive the events (because eventually that single page
will grow quite large and could become difficult to work with).</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/353042222014-11-26T16:46:13Z2014-11-26T16:46:13ZUnique Identifiers in Data Definitions<div><p>Hi Nick,</p>
<p>Just wanted to follow up to see if you had a chance to view my
<a href=
"http://help.hannonhill.com/discussions/how-do-i/14998-unique-identifiers-in-data-definitions#comment_35305350">
recent comment</a>.</p>
<p>Please let us know if you have any questions.</p>
<p>Thanks.</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/353042222014-12-01T17:09:07Z2014-12-01T17:09:08ZUnique Identifiers in Data Definitions<div><p>Thanks for all of your help Ryan.</p>
<p>I've attached some pictures of the project so hopefully it helps
illustrate the issue a little better. The first is a screenshot of
the web-application. This shows events that are upcoming for
student to attend.</p>
<p>The way that this web-page works is that it is all in one page.
You can see the source for the entire application here.
ecm.eng.auburn.edu/upc (If you'd like to interact with it, please
view it in Chrome > Inspect Element > Emulate an iPhone 5 or
6 > refresh)</p>
<p>Since it is all one page, we are very intent on having just one
simple page in cascade that the organization can use to update
their app. As you'll see on the second attachment, I have groups
for each section of the app; Events, Contests, Photos, Videos,
etc.</p>
<p>The issue we are having is for in situations when the
organization changes a attribute of the Event (location, time) and
for the native applications to be aware of that. The native
applications set notifications for the upcoming events, and need an
ID to check the db's for whether that exists.</p>
<p>I see what you mean about individual blocks but we are really
dug in on using the page how it is, simply just for the end-users.
The organization consists of a group of students who are there for
at most a year or two, so the aim is for them to be able to use it
with as little training as possible.</p>
<p>I think we have a working solution now that involves including a
check box-flag ordeal for the event signifying that the event has
changed in some fashion, that the JS could check for, delete the
old notification if there is one created, and then notify the user
so that they can make a new notification if they want.</p>
<p>Thanks again for all of your help.</p>
<p>-Nick</p></div>Nick tag:help-archives.hannonhill.com,2010-02-09:Comment/353042222014-12-01T18:42:26Z2014-12-01T18:42:26ZUnique Identifiers in Data Definitions<div><p>Hi Nick,</p>
<p>Thank you for the additional information.</p>
<p>Now that I think of it, I have an idea on how you can make each
event (or grouping for that matter) unique. In your Format, you
would come up with a way to hash the contents of a couple of fields
for each event, such as the title and time for the events. This
hash would be unique for each and would change if any of the fields
change.</p>
<p>If you are using Velocity, what you can do is set a variable to
the concatenation of the two field values and use Java's
<code>String.hashCode()</code> method. For example, something like
the following:</p>
<pre>
<code>#set ($uID = "${eventTitle.value}${eventDate.value}"}
## Output a hash code for the string.
$uID.hasCode()</code>
</pre>
<p>In XSLT, you could either use a Xalan JavaScript function, or
you might be able to use the <a href=
"http://www.w3schools.com/xsl/func_generateid.asp">generate-id
XPath function</a> and pass in a node set containing both the title
and date nodes.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/353042222014-12-01T20:55:07Z2014-12-01T20:55:10ZUnique Identifiers in Data Definitions<div><p>We thought about doing that, but on the Javascript end using
something like <a href=
"https://github.com/davidbau/seedrandom">https://github.com/davidbau/seedrandom</a></p>
<p>Which accepts any string as a seed to generate a random number
(and will always generate the same given the same seed).</p>
<p>The problem we ran into is that if they change one of the
attributes, such as the time, title, date..etc, that will then
generate a new ID. Which is helpful in creating a new notification
for the altered event, but how would we then know the id of the
event before it was altered to delete it's notification on the
native app?</p>
<p>I'm assuming this same issue is present with what you
mentioned.</p></div>Nick tag:help-archives.hannonhill.com,2010-02-09:Comment/353042222014-12-01T21:36:52Z2014-12-01T21:36:53ZUnique Identifiers in Data Definitions<div><p>Also, for Android, to set a pending notification the api accepts
only an int value. All the math aside, that means our ID would need
to result as a 9-digit int.</p></div>Nick tag:help-archives.hannonhill.com,2010-02-09:Comment/353042222014-12-03T14:32:58Z2014-12-03T14:32:58ZUnique Identifiers in Data Definitions<div><p>Thank you for the additional context, Nick, very helpful.</p>
<p>The only thing I can think of is to have a combination of the
solution I mentioned with <code>String.hashCode()</code> of the
important fields and a text field for the events to uniquely
identify them.</p>
<p>What you could do is use the "unique id" text field value as the
lookup key and store the hash code value. When you push updated
content, you would compare the hash code to what is already there
for that identifier and process accordingly. You could make this
anything really and if it needs to be an integer, also run it
through <code>String.hashCode()</code>, but instruct your users to
never change the value.</p>
<blockquote>
<p>Also, for Android, to set a pending notification the api accepts
only an int value. All the math aside, that means our ID would need
to result as a 9-digit int.</p>
</blockquote>
<p>Just to confirm, does it have to be a specific length, or just
an integer in general? <code>String.hashCode()</code> does result
in an integer but it could be negative, so you would just need to
run it through the Math Tool's <code>abs()</code> method:</p>
<pre>
<code>$_MathTool.abs($str.hashCode())</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffith