-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from swimlane/SPT-4113-bugfix-history-field
SPT-4113: Support for App and Record Revisions, along with history fields
- Loading branch information
Showing
20 changed files
with
1,325 additions
and
593 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from swimlane.core.cache import check_cache | ||
from swimlane.core.resolver import AppResolver | ||
from swimlane.core.resources.app_revision import AppRevision | ||
from swimlane.utils import one_of_keyword_only | ||
|
||
|
||
class AppRevisionAdapter(AppResolver): | ||
"""Handles retrieval of Swimlane App Revision resources""" | ||
|
||
def get_all(self): | ||
""" | ||
Gets all app revisions. | ||
Returns: | ||
AppRevision[]: Returns all AppRevisions for this Adapter's app. | ||
""" | ||
raw_revisions = self._swimlane.request('get', 'app/{0}/history'.format(self._app.id)).json() | ||
return [AppRevision(self._swimlane, raw) for raw in raw_revisions] | ||
|
||
def get(self, revision_number): | ||
""" | ||
Gets a specific app revision. | ||
Supports resource cache | ||
Keyword Args: | ||
revision_number (float): App revision number | ||
Returns: | ||
AppRevision: The AppRevision for the given revision number. | ||
""" | ||
key_value = AppRevision.get_unique_id(self._app.id, revision_number) | ||
return self.__get(app_id_revision=key_value) | ||
|
||
@check_cache(AppRevision) | ||
@one_of_keyword_only('app_id_revision') | ||
def __get(self, key, value): | ||
"""Underlying get method supporting resource cache.""" | ||
app_id, revision_number = AppRevision.parse_unique_id(value) | ||
app_revision_raw = self._swimlane.request('get', 'app/{0}/history/{1}'.format(app_id, revision_number)).json() | ||
return AppRevision(self._swimlane, app_revision_raw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from swimlane.core.resolver import AppResolver | ||
from swimlane.core.resources.record_revision import RecordRevision | ||
|
||
|
||
class RecordRevisionAdapter(AppResolver): | ||
"""Handles retrieval of Swimlane Record Revision resources""" | ||
|
||
def __init__(self, app, record): | ||
super(RecordRevisionAdapter, self).__init__(app) | ||
self.record = record | ||
|
||
def get_all(self): | ||
"""Get all revisions for a single record. | ||
Returns: | ||
RecordRevision[]: All record revisions for the given record ID. | ||
""" | ||
raw_revisions = self._swimlane.request('get', | ||
'app/{0}/record/{1}/history'.format(self._app.id, self.record.id)).json() | ||
return [RecordRevision(self._app, raw) for raw in raw_revisions] | ||
|
||
def get(self, revision_number): | ||
"""Gets a specific record revision. | ||
Keyword Args: | ||
revision_number (float): Record revision number | ||
Returns: | ||
RecordRevision: The RecordRevision for the given revision number. | ||
""" | ||
record_revision_raw = self._swimlane.request('get', | ||
'app/{0}/record/{1}/history/{2}'.format(self._app.id, | ||
self.record.id, | ||
revision_number)).json() | ||
return RecordRevision(self._app, record_revision_raw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from swimlane.core.resources.app import App | ||
from swimlane.core.resources.revision_base import RevisionBase | ||
|
||
|
||
class AppRevision(RevisionBase): | ||
""" | ||
Encapsulates a single revision returned from a History lookup. | ||
Attributes: | ||
Attributes: | ||
modified_date: The date this app revision was created. | ||
revision_number: The revision number of this app revision. | ||
status: Indicates whether this revision is the current revision or a historical revision. | ||
user: The user that saved this revision of the record. | ||
version: The App corresponding to the data contained in this app revision. | ||
""" | ||
|
||
# Separator for unique ids. Unlikely to be found in application ids. Although technically we do not currently | ||
# validate app ids in the backend for specific characters so this sequence could be found. | ||
SEPARATOR = ' --- ' | ||
|
||
@staticmethod | ||
def get_unique_id(app_id, revision_number): | ||
"""Returns the unique identifier for the given AppRevision.""" | ||
return '{0}{1}{2}'.format(app_id, AppRevision.SEPARATOR, revision_number) | ||
|
||
@staticmethod | ||
def parse_unique_id(unique_id): | ||
"""Returns an array containing two items: the app_id and revision number parsed from the given unique_id.""" | ||
return unique_id.split(AppRevision.SEPARATOR) | ||
|
||
@property | ||
def version(self): | ||
"""Returns an App from the _raw_version info in this app revision. Lazy loaded. Overridden from base class.""" | ||
if not self._version: | ||
self._version = App(self._swimlane, self._raw_version) | ||
return self._version | ||
|
||
def get_cache_index_keys(self): | ||
"""Returns cache index keys for this AppRevision.""" | ||
return { | ||
'app_id_revision': self.get_unique_id(self.version.id, self.revision_number) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.