Unique Identifiers in Data Definitions

Nick 's Avatar

Nick

17 Nov, 2014 03:42 PM

Hello all,

Here at Auburn University we are trying to create a system to alert students to upcoming events via mobile apps. We have developed a 'hybrid' app of sorts that uses a shared web UI that then bridges to the respective iOS and Android native wrapper applications. We have a JS system that checks with the native code to see if there are any reminders for events previously set based on a unique event ID.

For the end-users, they will be using a data definition to create and manage new events using data such as a picture, title, location, and date/time.

Is there a way to attach a unique persistent INT value to a data definition entry each time they create an event?

(Preferably a random or incremented number value)

Thank you,

Nick

  1. 1 Posted by Ryan Griffith on 17 Nov, 2014 04:19 PM

    Ryan Griffith's Avatar

    Hi Nick,

    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.

    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 id attribute) and the actual event data.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by Nick on 17 Nov, 2014 04:33 PM

    Nick 's Avatar

    Thanks for the speedy reply Ryan.

    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.

    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.

  3. 3 Posted by Ryan Griffith on 17 Nov, 2014 04:50 PM

    Ryan Griffith's Avatar

    Not a problem at all, Nick.

    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.

    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?

    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.

    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:

    • A folder(s) to contain the events
    • Each event would be a separate block or page that has the same data definition you use now, minus the repeating group
    • A page that contains a single DEFAULT region which has a Format and Index Block applied to it.
      • The Index Block will be indexing the folder containing the events (or the event Content Type if you are using pages)
      • The Format would generate your XML structure that is consumed by your webpage

    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).

    Thanks!

  4. Ryan Griffith closed this discussion on 26 Nov, 2014 04:45 PM.

  5. Ryan Griffith re-opened this discussion on 26 Nov, 2014 04:46 PM

  6. 4 Posted by Ryan Griffith on 26 Nov, 2014 04:46 PM

    Ryan Griffith's Avatar

    Hi Nick,

    Just wanted to follow up to see if you had a chance to view my recent comment.

    Please let us know if you have any questions.

    Thanks.

  7. 5 Posted by Nick on 01 Dec, 2014 05:09 PM

    Nick 's Avatar

    Thanks for all of your help Ryan.

    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.

    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)

    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.

    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.

    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.

    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.

    Thanks again for all of your help.

    -Nick

  8. 6 Posted by Ryan Griffith on 01 Dec, 2014 06:42 PM

    Ryan Griffith's Avatar

    Hi Nick,

    Thank you for the additional information.

    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.

    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 String.hashCode() method. For example, something like the following:

    #set ($uID = "${eventTitle.value}${eventDate.value}"}
    ## Output a hash code for the string.
    $uID.hasCode()
    

    In XSLT, you could either use a Xalan JavaScript function, or you might be able to use the generate-id XPath function and pass in a node set containing both the title and date nodes.

    Please let me know if you have any questions.

    Thanks!

  9. 7 Posted by Nick on 01 Dec, 2014 08:55 PM

    Nick 's Avatar

    We thought about doing that, but on the Javascript end using something like https://github.com/davidbau/seedrandom

    Which accepts any string as a seed to generate a random number (and will always generate the same given the same seed).

    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?

    I'm assuming this same issue is present with what you mentioned.

  10. 8 Posted by Nick on 01 Dec, 2014 09:36 PM

    Nick 's Avatar

    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.

  11. 9 Posted by Ryan Griffith on 03 Dec, 2014 02:32 PM

    Ryan Griffith's Avatar

    Thank you for the additional context, Nick, very helpful.

    The only thing I can think of is to have a combination of the solution I mentioned with String.hashCode() of the important fields and a text field for the events to uniquely identify them.

    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 String.hashCode(), but instruct your users to never change the value.

    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.

    Just to confirm, does it have to be a specific length, or just an integer in general? String.hashCode() does result in an integer but it could be negative, so you would just need to run it through the Math Tool's abs() method:

    $_MathTool.abs($str.hashCode())
    

    Please let me know if you have any questions.

    Thanks!

  12. Ryan Griffith closed this discussion on 19 Jan, 2015 04:30 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac