private void sendRecords(Cache cache) { Long groupId = LiferayServerContext.getGroupId(); List<DDLRecordCache> records = getLatestRecordsToSync(cache); DDLRecordService recordService = new DDLRecordService(SessionContext.createSessionFromCurrentSession()); for (DDLRecordCache cachedRecord : records) { try { Record record = cachedRecord.getRecord(); record.setCreatorUserId(SessionContext.getLoggedUser().getId()); final JSONObject serviceContextAttributes = new JSONObject(); serviceContextAttributes.put("userId", record.getCreatorUserId()); serviceContextAttributes.put("scopeGroupId", groupId); JSONObjectWrapper serviceContextWrapper = new JSONObjectWrapper(serviceContextAttributes); JSONObject jsonContent = cachedRecord.getJSONContent(); JSONObject jsonObject = saveOrUpdate(recordService, record, groupId, serviceContextWrapper, jsonContent); cachedRecord.setDirty(false); cachedRecord.setSyncDate(new Date()); cache.set(cachedRecord); } catch (Exception e) { LiferayLogger.e("Error syncing a record", e); } } }
private void sendDocuments(Cache cache) { long userId = SessionContext.getDefaultUserId(); long groupId = LiferayServerContext.getGroupId(); List<DocumentUploadCache> documentsToUpload = cache.get( DOCUMENT_UPLOAD, DocumentUploadCache.DIRTY + " = 1 " + "AND " + DocumentUploadCache.USER_ID + " = ? " + "AND " + DocumentUploadCache.GROUP_ID + " = ? ", userId, groupId); for (DocumentUploadCache document : documentsToUpload) { try { Map<String, Object> objectObjectHashMap = new HashMap<>(); DocumentField documentField = new DocumentField(objectObjectHashMap, new Locale("es")); documentField.createLocalFile(document.getPath()); UploadService uploadService = new UploadService(); JSONObject jsonObject = uploadService.uploadFile( documentField, document.getUserId(), document.getGroupId(), document.getRepositoryId(), document.getFolderId(), document.getFilePrefix()); document.setDirty(false); document.setSyncDate(new Date()); cache.set(document); } catch (Exception e) { LiferayLogger.e("Error sending documentsToUpload", e); } } }
private List<DDLRecordCache> getLatestRecordsToSync(Cache cache) { long groupId = LiferayServerContext.getGroupId(); return cache.get( DDL_RECORD, DDLRecordCache.DIRTY + " = 1 AND " + TableCache.GROUP_ID + " = ? ", groupId); }