From 8319fa14a830f39cf26bb807a4a9acb6aadee8b1 Mon Sep 17 00:00:00 2001 From: Enercido Alcantara Date: Fri, 19 Jan 2018 09:45:07 -0500 Subject: [PATCH] Added support for handle failed synchronization --- Entity/SyncDeleteState.php~ | 110 +++++++++++ Entity/SyncFailedItemState.php | 191 +++++++++++++++++++ Entity/SyncFailedItemState.php~ | 191 +++++++++++++++++++ Entity/SyncMapping.php~ | 110 +++++++++++ Entity/SyncNewItemState.php~ | 144 ++++++++++++++ Entity/SyncState.php~ | 85 +++++++++ README.md | 21 +- Repository/SyncFailedItemStateRepository.php | 41 ++++ 8 files changed, 891 insertions(+), 2 deletions(-) create mode 100644 Entity/SyncDeleteState.php~ create mode 100644 Entity/SyncFailedItemState.php create mode 100644 Entity/SyncFailedItemState.php~ create mode 100644 Entity/SyncMapping.php~ create mode 100644 Entity/SyncNewItemState.php~ create mode 100644 Entity/SyncState.php~ create mode 100755 Repository/SyncFailedItemStateRepository.php diff --git a/Entity/SyncDeleteState.php~ b/Entity/SyncDeleteState.php~ new file mode 100644 index 0000000..9a83c09 --- /dev/null +++ b/Entity/SyncDeleteState.php~ @@ -0,0 +1,110 @@ +id; + } + + /** + * @return SyncMapping + */ + public function getMapping() + { + return $this->mapping; + } + + /** + * @param SyncMapping $mapping + * @return SyncDeleteState + */ + public function setMapping($mapping) + { + $this->mapping = $mapping; + return $this; + } + + /** + * @return int + */ + public function getClassId() + { + return $this->classId; + } + + /** + * @param int $classId + * @return SyncDeleteState + */ + public function setClassId($classId) + { + $this->classId = $classId; + return $this; + } + + /** + * @return int + */ + public function getTimestamp() + { + return $this->timestamp; + } + + /** + * @param int $timestamp + * @return SyncDeleteState + */ + public function setTimestamp($timestamp) + { + $this->timestamp = $timestamp; + return $this; + } + +} diff --git a/Entity/SyncFailedItemState.php b/Entity/SyncFailedItemState.php new file mode 100644 index 0000000..7088247 --- /dev/null +++ b/Entity/SyncFailedItemState.php @@ -0,0 +1,191 @@ +id; + } + + /** + * Set uuid + * + * @param string $uuid + * + * @return SyncFailedItemState + */ + public function setUuid($uuid) + { + $this->uuid = $uuid; + + return $this; + } + + /** + * Get uuid + * + * @return string + */ + public function getUuid() + { + return $this->uuid; + } + + /** + * Set classId + * + * @param integer $classId + * + * @return SyncFailedItemState + */ + public function setClassId($classId) + { + $this->classId = $classId; + + return $this; + } + + /** + * Get classId + * + * @return integer + */ + public function getClassId() + { + return $this->classId; + } + + /** + * Set timestamp + * + * @param integer $timestamp + * + * @return SyncFailedItemState + */ + public function setTimestamp($timestamp) + { + $this->timestamp = $timestamp; + + return $this; + } + + /** + * Get timestamp + * + * @return integer + */ + public function getTimestamp() + { + return $this->timestamp; + } + + /** + * Set errors + * + * @param string $errors + * + * @return SyncFailedItemState + */ + public function setErrors($errors) + { + $this->errors = $errors; + + return $this; + } + + /** + * Get errors + * + * @return string + */ + public function getErrors() + { + return $this->errors; + } + + /** + * Set mapping + * + * @param \NTI\SyncBundle\Entity\SyncMapping $mapping + * + * @return SyncFailedItemState + */ + public function setMapping(\NTI\SyncBundle\Entity\SyncMapping $mapping = null) + { + $this->mapping = $mapping; + + return $this; + } + + /** + * Get mapping + * + * @return \NTI\SyncBundle\Entity\SyncMapping + */ + public function getMapping() + { + return $this->mapping; + } +} diff --git a/Entity/SyncFailedItemState.php~ b/Entity/SyncFailedItemState.php~ new file mode 100644 index 0000000..7088247 --- /dev/null +++ b/Entity/SyncFailedItemState.php~ @@ -0,0 +1,191 @@ +id; + } + + /** + * Set uuid + * + * @param string $uuid + * + * @return SyncFailedItemState + */ + public function setUuid($uuid) + { + $this->uuid = $uuid; + + return $this; + } + + /** + * Get uuid + * + * @return string + */ + public function getUuid() + { + return $this->uuid; + } + + /** + * Set classId + * + * @param integer $classId + * + * @return SyncFailedItemState + */ + public function setClassId($classId) + { + $this->classId = $classId; + + return $this; + } + + /** + * Get classId + * + * @return integer + */ + public function getClassId() + { + return $this->classId; + } + + /** + * Set timestamp + * + * @param integer $timestamp + * + * @return SyncFailedItemState + */ + public function setTimestamp($timestamp) + { + $this->timestamp = $timestamp; + + return $this; + } + + /** + * Get timestamp + * + * @return integer + */ + public function getTimestamp() + { + return $this->timestamp; + } + + /** + * Set errors + * + * @param string $errors + * + * @return SyncFailedItemState + */ + public function setErrors($errors) + { + $this->errors = $errors; + + return $this; + } + + /** + * Get errors + * + * @return string + */ + public function getErrors() + { + return $this->errors; + } + + /** + * Set mapping + * + * @param \NTI\SyncBundle\Entity\SyncMapping $mapping + * + * @return SyncFailedItemState + */ + public function setMapping(\NTI\SyncBundle\Entity\SyncMapping $mapping = null) + { + $this->mapping = $mapping; + + return $this; + } + + /** + * Get mapping + * + * @return \NTI\SyncBundle\Entity\SyncMapping + */ + public function getMapping() + { + return $this->mapping; + } +} diff --git a/Entity/SyncMapping.php~ b/Entity/SyncMapping.php~ new file mode 100644 index 0000000..04ac4d2 --- /dev/null +++ b/Entity/SyncMapping.php~ @@ -0,0 +1,110 @@ +id; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return SyncMapping + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getClass() + { + return $this->class; + } + + /** + * @param string $class + * @return SyncMapping + */ + public function setClass($class) + { + $this->class = $class; + return $this; + } + + /** + * @return string + */ + public function getSyncService() + { + return $this->syncService; + } + + /** + * @param string $syncService + * @return SyncMapping + */ + public function setSyncService($syncService) + { + $this->syncService = $syncService; + return $this; + } + + +} diff --git a/Entity/SyncNewItemState.php~ b/Entity/SyncNewItemState.php~ new file mode 100644 index 0000000..e6e46fb --- /dev/null +++ b/Entity/SyncNewItemState.php~ @@ -0,0 +1,144 @@ +id; + } + + /** + * @param int $id + * @return SyncNewItemState + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getUuid() + { + return $this->uuid; + } + + /** + * @param string $uuid + * @return SyncNewItemState + */ + public function setUuid($uuid) + { + $this->uuid = $uuid; + return $this; + } + + /** + * @return SyncMapping + */ + public function getMapping() + { + return $this->mapping; + } + + /** + * @param SyncMapping $mapping + * @return SyncNewItemState + */ + public function setMapping($mapping) + { + $this->mapping = $mapping; + return $this; + } + + /** + * @return int + */ + public function getClassId() + { + return $this->classId; + } + + /** + * @param int $classId + * @return SyncNewItemState + */ + public function setClassId($classId) + { + $this->classId = $classId; + return $this; + } + + /** + * @return int + */ + public function getTimestamp() + { + return $this->timestamp; + } + + /** + * @param int $timestamp + * @return SyncNewItemState + */ + public function setTimestamp($timestamp) + { + $this->timestamp = $timestamp; + return $this; + } + +} diff --git a/Entity/SyncState.php~ b/Entity/SyncState.php~ new file mode 100644 index 0000000..1e47788 --- /dev/null +++ b/Entity/SyncState.php~ @@ -0,0 +1,85 @@ +id; + } + + /** + * @return SyncMapping + */ + public function getMapping() + { + return $this->mapping; + } + + /** + * @param SyncMapping $mapping + * @return SyncState + */ + public function setMapping($mapping) + { + $this->mapping = $mapping; + return $this; + } + + /** + * @return int + */ + public function getTimestamp() + { + return $this->timestamp; + } + + /** + * @param int $timestamp + * @return SyncState + */ + public function setTimestamp($timestamp) + { + $this->timestamp = $timestamp; + return $this; + } + +} diff --git a/README.md b/README.md index c9b83a8..5f3238c 100755 --- a/README.md +++ b/README.md @@ -187,17 +187,34 @@ After receiving the request, if a mapping with the specified name exists, the sy }, ... ], + "failedItems": [ + { + "id": 7, + "uuid": "abcdefg-123456-hifgxyz-78901", + "mapping": { + "id": 9, + "name": "Product", + "class": "AppBundle\\Entity\\Product\\Product", + "sync_service": " ... " + }, + "classId": 137, + "timestamp": 1512080747, + "errors": "{"has_error":true,"additional_errors":null,"code":403,"message":"This inventory report is already closed. Further operations are not allowed.","data":null,"redirect":null}" + }, + ... + ], "_real_last_timestamp": 1512092445 } } ``` -The server will return the both the `changes` , `newItems`, and the `deletes`. The `changes` will contain the `data` portion of the array returned by +The server will return the both the `changes` , `newItems`, `failedItems` ,and the `deletes`. The `changes` will contain the `data` portion of the array returned by the repository's implementation of `SyncRepositoryInterface`. The `deletes` will contain the list of `SyncDeleteState` that were recorded since the specified timestamp. The `newItems` will contain the list of `SyncNewItemState` which means the new items that were created since the provided timestamp including the UUID that was given at the time (This is helpful to third party devices when first pulling the information they can verify if an item was already created -but they don't have the ID of that item in their local storage and avoid creating duplicates in the server) +but they don't have the ID of that item in their local storage and avoid creating duplicates in the server). The `failedItems` will contain the list of `SyncFailedItemState`, each item in this list +contains an `errors` JSON property with the list of errors founds processing the creation or update of the entity. The `_real_last_timestamp` should be used as it can help with paginating the results for a full-sync and help the client get the real last timestamp of the last object in the response. This has to be obtained in the repository and can be done diff --git a/Repository/SyncFailedItemStateRepository.php b/Repository/SyncFailedItemStateRepository.php new file mode 100755 index 0000000..da12c3e --- /dev/null +++ b/Repository/SyncFailedItemStateRepository.php @@ -0,0 +1,41 @@ +createQueryBuilder('s'); + $qb ->innerJoin('s.mapping', 'm') + ->andWhere('m.name = :mappingName') + ->setParameter('mappingName', $mappingName) + ->andWhere('s.timestamp >= :timestamp') + ->setParameter('timestamp', $timestamp) + ->orderBy('s.timestamp', 'asc'); + return $qb->getQuery()->getResult(); + } + + public function findByUuId($id){ + $qb = $this->getEntityManager()->createQueryBuilder(); + $qb->select('item') + ->from('NTISyncBundle:SyncFailedItemState', 'item') + ->andWhere( + $qb->expr()->eq('binary(item.uuid)', $qb->expr()->literal($id)) + ); + + try { + return $qb->getQuery()->getOneOrNullResult(); + }catch (NonUniqueResultException $e){ + return null; + } + } +}