Jsreport online - error Unable to insert an entity with new tenant owner during the import: Error: Entity with name "...." already exists ...
-
In my Jsreport online account, i have a root folder per tenant. Each tenant have their own isolated templates.
In my deploy pipeline, I'm trying to upload templates for Tenant1, without affecting other tenant folders. I would like to overwrite the whole content of Tenant1 folder.
When i use "jsreport import" cli, it works the first time (when Tenant1 folder is empty), but on subsequent import, it gives me this error:
Unable to insert an entity with new tenant owner during the import: Error: Entity with name "...." already exists ...
I cannot use the --fullImport switch as it would delete other tenant folders.
And jsreport import doesn't support having both --fullImport and --targetFolder at the same time.Any solutions to this ?
-
hi @guilmori
we would like to investigate the problem here more deeply, can you please share the zip you are trying to import into your account? we would like to replicate the import and come up with the best solution, or the best workaround if needed. you can share with me the zip privately at my email bjrmatos@gmail.com.
thanks
-
thanks a lot for the zip and the details, we have some things to still think it through to improve the import/export flow in the jsreportonline, the problem here is that we have some issues regarding the detection of existing entities while re-importing. we will analyze the case deeper and try to provide a general solution but for now you can do this in your deploy pipeline:
- first you need to ensure that the target folder "Tenant1" does not exists in your jo account, this step is important, the import will only work correctly if the tenant folder does not exists before the import, you can add a step in your deploy pipeline which deletes the "Tenant1" folder with the http api, basically you need to send a
DELETE
request to your jsreportonline account for the tenant folder, the request url looks like this:
method:
DELETE
url:https://youraccount.jsreportonline.net/odata/folders(_idOfTenant1Folder)
you can take the _id of the folder you want to delete from the list of folders, which will be available to you with a
GET
https://youraccount.jsreportonline.net/odata/folders
, also if you know the shortid of the folder you can also get the _id of the folder by doingGET
http://jsreport-host/odata/templates?$filter=shortid eq 'shortid'
- after that you can import your zip normally with the same command you are already executing
of course first do some tests before using this in production, let me know how it goes and if you have some problems with it.
- first you need to ensure that the target folder "Tenant1" does not exists in your jo account, this step is important, the import will only work correctly if the tenant folder does not exists before the import, you can add a step in your deploy pipeline which deletes the "Tenant1" folder with the http api, basically you need to send a
-
Thanks, i got it working by deleting the folder via http api prior to import.
I still get these error no matter what, which are from settings file, but it seems to work nonetheless.
2020-04-24T19:40:42.9638086Z import logs:
2020-04-24T19:40:42.9638637Z --------------------
2020-04-24T19:40:42.9639098Z Unable to insert an entity with new tenant owner during the import: Error: Entity with shortid "0BaIAR_" already exists.
2020-04-24T19:40:42.9639714Z Unable to insert an entity with new tenant owner during the import: Error: Entity with shortid "B2EOzBc" already exists.
2020-04-24T19:40:42.9640276Z Unable to insert an entity with new tenant owner during the import: Error: Entity with shortid "xJcKcMc" already exists.
2020-04-24T19:40:42.9640861Z Unable to insert an entity with new tenant owner during the import: Error: Entity with shortid "8fx_6o7" already exists.
2020-04-24T19:40:42.9641283Z Info: import finished
2020-04-24T19:40:42.9641686Z --------------------
-
@guilmori glad that it works for you. yes, those warnings are expected too, we have a minor issue with the export that includes the settings which should not be there in the zip, so ignore those warnings and we will fix that also.
-
If it can help someone, here is my powershell script to delete the folder via the http api
$credPair = "$(JsReport.Username):$(JsReport.Password)" $encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair)) $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("Authorization", "Basic $encodedCredentials") $tenantFolderShortid = "$(JsReport.TenantFolderShortid)" $response = Invoke-RestMethod -Uri "https://xxx.jsreportonline.net/odata/folders?`$filter=shortid eq '$tenantFolderShortid'" -Method 'GET' -Headers $headers $response | ConvertTo-Json if($response.value[0]._id) { $folderid = $response.value[0]._id Invoke-RestMethod -Uri "https://xxx.jsreportonline.net/odata/folders($folderid)" -Method 'DELETE' -Headers $headers; }
-
Me again :-)
Now let's say we have a TEST en PROD environment.
I won't be able to import both PROD/Tenant1/ and TEST/Tenant1/, because of duplicate shortId ...
Would you have any suggestion for that use case ?
I guess the easy answer is to have 2 jsreport online accounts.
-
we think that using a separate jsreportonline account is the best here, because it is more secure so you don't accidentally mess with that kind of duplicates.