Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions demos/createSolution/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<!doctype html>
<html lang="en" dir="ltr">

<head>
<meta charset="utf-8"/>
<meta charset="utf-8" />
<title>createSolution example</title>
<!--
| Copyright 2023 Esri
Expand All @@ -18,11 +19,13 @@
| See the License for the specific language governing permissions and
| limitations under the License.
-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
.indent {
margin-left: 20px;
}

#subgroupIdsDiv {
display: none;
}
Expand All @@ -31,6 +34,7 @@
var goFcn;
</script>
</head>

<body>
<h3>Create a Solution</h3>
<p>Create a solution item from the contents of a group or from a single item and its dependencies.</p>
Expand All @@ -54,7 +58,7 @@ <h3>Create a Solution</h3>

<br /><br />

<div class="section-title">Credentials in source organization</div>
<div class="section-title">Credentials for organization</div>

<div class="labeledItem">
<label for="srcUsername">Username:&nbsp;</label>
Expand All @@ -68,7 +72,7 @@ <h3>Create a Solution</h3>
<label for="srcPortal">Portal:&nbsp;</label>
<input type="text" id="srcPortal" style="width:256px" placeholder="https://www.arcgis.com">
</div>

<!--
<br/><br/>

<div class="section-title">Credentials in destination organization</div>
Expand All @@ -87,7 +91,8 @@ <h3>Create a Solution</h3>
</div>

<br/><br/>

-->
<br /><br />
<button class="btn btn-default" onclick="goFcn()">Create Solution</button>
</div>

Expand All @@ -106,4 +111,5 @@ <h3>Create a Solution</h3>

</script>
</body>
</html>

</html>
28 changes: 20 additions & 8 deletions demos/createSolution/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,28 @@ function go () {
portal: srcPortal
});

// Dest credentials
const destHtmlValue = htmlUtil.getHTMLValue("destPortal");
// Dest credentials (same as Source to keep demo app working and beahvior similiar to Creation app)
const destHtmlValue = htmlUtil.getHTMLValue("srcPortal");
const destPortalStr = destHtmlValue.endsWith('/') ? destHtmlValue.slice(0, -1) : destHtmlValue;
const destPortal = (destPortalStr || "https://www.arcgis.com") + "/sharing/rest";
const destCreds = new common.UserSession({
username: htmlUtil.getHTMLValue("destUsername"),
password: htmlUtil.getHTMLValue("destPassword"),
username: htmlUtil.getHTMLValue("srcUsername"),
password: htmlUtil.getHTMLValue("srcPassword"),
portal: destPortal
});

/*
// Dest credentials (uncomment this and html if you want to target different org for test purproses)
const destHtmlValue = htmlUtil.getHTMLValue("destPortal");
const destPortalStr = destHtmlValue.endsWith('/') ? destHtmlValue.slice(0, -1) : destHtmlValue;
const destPortal = (destPortalStr || "https://www.arcgis.com") + "/sharing/rest";
const destCreds = new common.UserSession({
username: htmlUtil.getHTMLValue("destUsername"),
password: htmlUtil.getHTMLValue("destPassword"),
portal: destPortal
});
*/

// Create!
main.createSolution(
id,
Expand All @@ -73,10 +85,10 @@ function go () {
document.getElementById("output").innerHTML = "Creating..." + percentDone.toFixed().toString() + "%";
},
subgroupIds
).then(function (html){
reportElapsedTime(startTime);
document.getElementById("output").innerHTML = html;
},
).then(function(html) {
reportElapsedTime(startTime);
document.getElementById("output").innerHTML = html;
},
error => {
var message = error?.error || JSON.stringify(error) || "Unspecified error";
if (error.itemIds) {
Expand Down
80 changes: 79 additions & 1 deletion packages/creator/src/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ import {
generateSourceThumbnailUrl,
getBlobAsFile,
getFilenameFromUrl,
getGroup,
getGroupBase,
getGroupContents,
getItem,
getItemBase,
getItemDataAsJson,
getPortal,
getSubgroupIds,
getUser,
Expand All @@ -43,6 +46,7 @@ import {
IItem,
removeItem,
sanitizeJSON,
searchItems,
setLocationTrackingEnabled,
UserSession,
} from "@esri/solution-common";
Expand Down Expand Up @@ -97,7 +101,22 @@ export async function createSolution(
createOptions.itemIds = [sourceId];
getItemBase(sourceId, srcAuthentication).then(
// Update the createOptions with values from the item
(itemBase) => resolve(_applySourceToCreateOptions(createOptions, itemBase, srcAuthentication, false)),
(itemBase) => {
if (
itemBase?.type === "Solution" &&
itemBase?.typeKeywords &&
itemBase?.typeKeywords.includes("Deployed")
) {
_updateCreateOptionForReDeployedTemplate(sourceId, srcAuthentication, createOptions, itemBase).then(
(updatedCreateOptions) => {
resolve(_applySourceToCreateOptions(updatedCreateOptions, itemBase, srcAuthentication, false));
},
reject,
);
} else {
resolve(_applySourceToCreateOptions(createOptions, itemBase, srcAuthentication, false));
}
},
reject,
);
});
Expand Down Expand Up @@ -348,3 +367,62 @@ export function _getDeploymentProperty(desiredTagPrefix: string, tags: string[])
return null;
}
}

export async function _updateCreateOptionForReDeployedTemplate(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please add function documentation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right! thanks for the reminder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added function doc.

sourceId: string,
authentication: UserSession,
createOptions: ICreateSolutionOptions,
itemBase: IItem,
): Promise<ICreateSolutionOptions> {
try {
const existingItems = [];

const itemData = await getItemDataAsJson(sourceId, authentication);
//Check if any of the item ids is deleted, if so remove from the list
for (const template of itemData.templates) {
try {
if (template.type === "Group") {
const exists = await getGroup(template.itemId, { authentication: authentication });
if (exists) {
existingItems.push(exists.id);
}
} else {
const exists = await getItem(template.itemId, { authentication: authentication });
if (exists) {
existingItems.push(exists.id);
}
}
} catch (error) {
// Handle the error if item has been deleted
console.error("An error occurred while fetching item:", template.itemId);
console.log(template);
}
}
//Add all valid items to createOptions items list
createOptions.itemIds = existingItems.map((template) => {
return template.itemId;
});

try {
//query the folder
const response = await searchItems({
q: `ownerfolder:${itemBase.ownerFolder}`,
authentication: authentication,
});

response.results.forEach((result) => {
// See if there are new items in the folder, if so add them to the itemIds
if (!createOptions.itemIds.includes(result.id) && result.type !== "Solution") {
createOptions.itemIds.push(result.id);
}
});
} catch (error) {
// Handle any errors
console.error("An error occurred during the search:", error);
}
} catch (error) {
console.error("An error occurred during get item data:", error);
}

return createOptions;
}
Loading