This commit is contained in:
Isaiah Williams 2018-09-30 11:40:25 -05:00 коммит произвёл GitHub
Родитель 6aec2f987b
Коммит 1a1d4a6321
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
163 изменённых файлов: 10482 добавлений и 316 удалений

28
.github/ISSUE_TEMPLATE/BUG_REPORT.md поставляемый Normal file
Просмотреть файл

@ -0,0 +1,28 @@
---
name: Bug report
about: Create a report to help us improve
---
# Steps to reproduce
> What steps can reproduce the defect?
> Please share the setup, sample project, version of Java etc.
## Expected behavior
> Share the expected output
## Actual behavior
> What is the behavior observed?
## Diagnostic logs
> Please share test platform diagnostics logs.
> The logs may contain test assembly paths, kindly review and mask those before sharing.
## Environment
> Please share additional details about your environment.
> Version

19
.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
---
name: Feature request
about: Suggest an idea for this project
---
# Feature Request
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I am always frustrated when [...]
**Describe the solution you would like**
A clear and concise description of what you want to happen.
**Describe alternatives you have considered**
A clear and concise description of any alternative solutions or features you have considered.
**Additional context**
Add any other context or screenshots about the feature request here.

7
.github/PULL_REQUEST_TEMPLATE.md поставляемый Normal file
Просмотреть файл

@ -0,0 +1,7 @@
# Description
Please add a meaningful description for this change. Ensure the PR has required unit tests.
## Related issue
Kindly link any related issues (e.g. Fixes #xyz).

382
.gitignore поставляемый
Просмотреть файл

@ -1,330 +1,106 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# Compiled class file
*.class
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
# Log file
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# BlueJ files
*.ctxt
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# Visual Studio Trace Files
*.e2e
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# TFS 2012 Local Workspace
$tf/
.classpath
.metadata
.project
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# Guidance Automation Toolkit
*.gpState
# External tool builders
.externalToolBuilders/
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# Locally stored "Eclipse launch configurations"
*.launch
# JustCode is a .NET coding add-in
.JustCode
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# TeamCity is a build add-in
_TeamCity*
# CDT-specific (C/C++ Development Tooling)
.cproject
# DotCover is a Code Coverage Tool
*.dotCover
# CDT- autotools
.autotools
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Java annotation processor (APT)
.factorypath
# Visual Studio code coverage results
*.coverage
*.coveragexml
# PDT-specific (PHP Development Tools)
.buildpath
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# sbteclipse plugin
.target
# MightyMoose
*.mm.*
AutoTest.Net/
# Tern plugin
.tern-project
# Web workbench (sass)
.sass-cache/
# TeXlipse plugin
.texlipse
# Installshield output folder
[Ee]xpress/
# STS (Spring Tool Suite)
.springBeans
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Code Recommenders
.recommenders/
# Click-Once directory
publish/
# Annotation Processing
.apt_generated/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# IntelliJ IDEA Configs
.idea
partnersdk.iml

26
.vscode/launch.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "externalTerminal",
"stopOnEntry": false,
"mainClass": "",
"args": ""
},
{
"type": "java",
"name": "Debug (Launch)-Program<Samples>",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "externalTerminal",
"stopOnEntry": false,
"mainClass": "com.microsoft.store.partnercenter.samples.Program",
"args": "",
"projectName": "Samples"
}
]
}

3
.vscode/settings.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}

3
CODE_OF_CONDUCT.md Normal file
Просмотреть файл

@ -0,0 +1,3 @@
# Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

80
CONTRIBUTING.md Normal file
Просмотреть файл

@ -0,0 +1,80 @@
# Contributing to Partner Center Java SDK Samples
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to and actually do, grant us
the rights to use your contribution. View the [Contributor License Agreement](https://cla.microsoft.com) for more details.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
- [Code of Conduct](#code-of-conduct)
- [Issues and Bugs](#finding-issues)
- [Feature Requests](#requesting-features)
- [Submission Guidelines](#submission-guidelines)
## Code of Conduct
Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
## Finding Issues
If you find a bug in the source code or a mistake in the documentation, you can help us by
[submitting an issue](#submitting-an-issue) to the GitHub Repository. Even better, you can
[submit a Pull Request](#submitting-a-pull-request) with a fix.
## Requesting Features
You can *request* a new feature by [submitting an issue](#submitting-an-issue) to the GitHub
Repository. If you would like to *implement* a new feature, please submit an issue with
a proposal for your work first, to be sure that we can use it.
**Small Features** can be crafted and directly [submitted as a Pull Request](#submitting-a-pull-request).
## Submission Guidelines
### Submitting an Issue
Before you submit an issue, search the archive, maybe your question was already answered.
If your issue appears to be a bug and hasn't been reported, open a new issue.
Help us to maximize the effort we can spend fixing issues and add new
features, by not reporting duplicate issues. Providing the following information will increase the
chances of your issue being dealt with quickly:
- **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
- **Version** - what version is affected (e.g. 0.1.2)
- **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
- **Browsers and Operating System** - is this a problem with all browsers?
- **Reproduce the Error** - provide a live example or an unambiguous set of steps
- **Related Issues** - has a similar issue been reported before?
- **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
causing the problem (line of code or commit)
You can file new issues by providing the above information at the [corresponding repository's issues link](https://github.com/Microsoft/Partner-Center-Java-Samples/issues/new).
### Submitting a Pull Request
Before you submit your Pull Request (PR) consider the following guidelines:
- [Search the repository](https://github.com/Microsoft/Partner-Center-Java-Samples/pulls) for an open or closed PR
that relates to your submission. You don't want to duplicate effort.
- Make your changes in a new git fork:
- Commit your changes using a descriptive commit message
- Push your fork to GitHub:
- In GitHub, create a pull request
- If we suggest changes then:
- Make the required updates.
- Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
```shell
git rebase master -i
git push -f
```
That is it! Thank you for your contribution!

Просмотреть файл

@ -1,14 +1,3 @@
# Partner Center Java SDK Samples
# Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
This repository contains a sample console application use to test the Partner Center Java SDK.

69
pom.xml Normal file
Просмотреть файл

@ -0,0 +1,69 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.store</groupId>
<artifactId>partnercenter-samples</artifactId>
<version>1.8.0</version>
<packaging>jar</packaging>
<name>Samples</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>com.microsoft.store</groupId>
<artifactId>partnercenter</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

Просмотреть файл

@ -0,0 +1,94 @@
// -----------------------------------------------------------------------
// <copyright file="AadUserLoginHandler.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.joda.time.DateTime;
import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
import com.microsoft.store.partnercenter.AuthenticationToken;
import com.microsoft.store.partnercenter.IAadLoginHandler;
import com.microsoft.store.partnercenter.samples.configuration.ConfigurationHolder;
public class AadUserLoginHandler
implements IAadLoginHandler
{
/**
* Logs into Azure active directory.
*
* @return The authentication result.
*/
@Override
public AuthenticationToken authenticate()
{
// async
// read AAD configuration
String authority =
ConfigurationHolder.getInstance().getConfiguration().getPartnerServiceSettings().get( "AuthenticationAuthorityEndpoint" );
String commonDomain =
ConfigurationHolder.getInstance().getConfiguration().getPartnerServiceSettings().get( "CommonDomain" );
String resourceUrl =
ConfigurationHolder.getInstance().getConfiguration().getUserAuthentication().get( "ResourceUrl" );
String clientId =
ConfigurationHolder.getInstance().getConfiguration().getUserAuthentication().get( "ClientId" );
String userName =
ConfigurationHolder.getInstance().getConfiguration().getUserAuthentication().get( "UserName" );
String password =
ConfigurationHolder.getInstance().getConfiguration().getUserAuthentication().get( "Password" );
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try
{
URI addAuthority = new URI( authority ).resolve( new URI( commonDomain ) );
service = Executors.newFixedThreadPool( 1 );
context = new AuthenticationContext( addAuthority.toString(), false, service );
Future<AuthenticationResult> future =
context.acquireToken( resourceUrl, clientId, userName, password, null );
result = future.get();
}
catch ( URISyntaxException e )
{
e.printStackTrace();
}
catch ( MalformedURLException e )
{
e.printStackTrace();
}
catch ( InterruptedException e )
{
e.printStackTrace();
}
catch ( ExecutionException e )
{
e.printStackTrace();
}
finally
{
service.shutdown();
}
if ( result == null )
{
throw new NullPointerException( "authentication result was null" );
}
return new AuthenticationToken( result.getAccessToken(), new DateTime( result.getExpiresOnDate() ) );
}
}

Просмотреть файл

@ -0,0 +1,45 @@
// -----------------------------------------------------------------------
// <copyright file="AggregatePartnerScenario.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples;
import java.text.MessageFormat;
import java.util.List;
import com.microsoft.store.partnercenter.samples.scenarioexecution.AggregateScenarioExecutionStrategy;
/**
* A scenarios that is composed of one or more sub-scenarios.
*/
public class AggregatePartnerScenario
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #AggregatePartnerScenario} class.
*
* @param title The scenario title.
* @param childScenarios A list of child scenarios.
* @param context The scenario context.
*/
public AggregatePartnerScenario( String title, List<IPartnerScenario> childScenarios, IScenarioContext context )
{
super( title, context, new AggregateScenarioExecutionStrategy(), childScenarios );
}
/**
* Runs the aggregate scenario.
*/
@Override
protected void runScenario()
{
for ( int i = 0; i < this.getChildren().size(); ++i )
{
// display the child scenarios
System.out.println( MessageFormat.format( "{0}: {1}", i + 1, this.getChildren().get( i ).getTitle() ) );
}
}
}

Просмотреть файл

@ -0,0 +1,687 @@
// -----------------------------------------------------------------------
// <copyright file="BasePartnerScenario.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples;
import java.text.MessageFormat;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.subscriptions.Subscription;
import com.microsoft.store.partnercenter.samples.scenarioexecution.IScenarioExecutionStrategy;
import com.microsoft.store.partnercenter.samples.scenarioexecution.PromptExecutionStrategy;
import com.microsoft.store.partnercenter.utils.StringHelper;
/**
* The base class for partner scenarios. Provides common behavior for all partner scenarios.
*/
public abstract class BasePartnerScenario
implements IPartnerScenario
{
/**
* Initializes a new instance of the {@link #BasePartnerScenario} class.
*
* @param title The scenario title.
* @param context The scenario context.
* @param executionStrategy The scenario execution strategy.
* @param childScenarios The child scenarios attached to the current scenario.
*/
public BasePartnerScenario( String title, IScenarioContext context )
{
this( title, context, null, null );
}
public BasePartnerScenario( String title, IScenarioContext context, IScenarioExecutionStrategy executionStrategy )
{
this( title, context, executionStrategy, null );
}
public BasePartnerScenario( String title, IScenarioContext context, IScenarioExecutionStrategy executionStrategy,
List<IPartnerScenario> childScenarios )
{
if ( StringHelper.isNullOrWhiteSpace( title ) )
{
throw new IllegalArgumentException( "title has to be set" );
}
if ( context == null )
{
throw new IllegalArgumentException( "context can't be null" );
}
this.setTitle( title );
this.setContext( context );
this.setExecutionStrategy( executionStrategy != null ? executionStrategy : new PromptExecutionStrategy() );
this.setChildren( childScenarios );
}
/**
* Gets the scenario title.
*/
private String __Title;
public String getTitle()
{
return __Title;
}
public void setTitle( String value )
{
__Title = value;
}
/**
* Gets the children scenarios of the current scenario.
*/
private List<IPartnerScenario> __Children;
public List<IPartnerScenario> getChildren()
{
return __Children;
}
public void setChildren( List<IPartnerScenario> value )
{
__Children = value;
}
/**
* Gets the scenario context.
*/
private IScenarioContext __Context;
public IScenarioContext getContext()
{
return __Context;
}
public void setContext( IScenarioContext value )
{
__Context = value;
}
/**
* Gets or sets the scenario execution behavior.
*/
private IScenarioExecutionStrategy __ExecutionStrategy;
private IScenarioExecutionStrategy getExecutionStrategy()
{
return __ExecutionStrategy;
}
private void setExecutionStrategy( IScenarioExecutionStrategy value )
{
__ExecutionStrategy = value;
}
/**
* Runs the scenario.
*/
public void run()
{
do
{
System.out.println();
System.out.println( new String( new char[80] ).replace( '\0', '-' ) );
System.out.println( this.getTitle() );
System.out.println( new String( new char[80] ).replace( '\0', '-' ) );
System.out.println();
try
{
this.runScenario();
}
catch ( Exception exception )
{
this.getContext().getConsoleHelper().error( exception.toString() );
}
System.out.println();
}
while ( !this.getExecutionStrategy().isScenarioComplete( this ) );
}
/**
* Obtains the availability ID to work with from the configuration if set there or prompts the user to enter it.
*
* @return: The availability identifier.
*/
protected String obtainAvailabilityId()
{
return this.obtainAvailabilityId(null);
}
/**
* Obtains the availability ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return: The availability identifier.
*/
protected String obtainAvailabilityId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get("DefaultAvailabilityId"),
"Availability Id",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the availability ID" : promptMessage,
"The Availability ID can't be empty");
}
/**
* Obtain an Azure Subscription Id for provision status with the configuration if set there or prompts the user to enter it.
*
* @return: An Azure subscription identifier.
*/
protected String obtainAzureSubscriptionId()
{
return this.obtainAzureSubscriptionId(null);
}
/**
* Obtain an Azure Subscription Id for provision status with the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return: An Azure subscription identifier.
*/
protected String obtainAzureSubscriptionId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get("DefaultAzureSubscriptionId"),
"Quantity",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the Azure Subscription Id" : promptMessage,
"The Azure Subscription Id can't be empty");
}
/**
* Obtains a tracking ID to work with from the configuration if set there or prompts the user to enter it.
*
* @return: A batch upload status tracking ID.
*/
protected String obtainBatchUploadStatusTrackingId()
{
return this.obtainBatchUploadStatusTrackingId(null);
}
/**
* Obtains a tracking ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return: A batch upload status tracking ID.
*/
protected String obtainBatchUploadStatusTrackingId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get("DefaultBatchUploadStatusTrackingId"),
"Batch Upload Status Tracking Id",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the Batch Upload Status Tracking ID" : promptMessage,
"The Batch Upload Status Tracking ID can't be empty");
}
/**
* Obtain an cart ID to work with the configuration if set there or prompts the user to enter it.
*
* @return: The cart identifier
*/
protected String obtainCartId()
{
return this.obtainCartId(null);
}
/**
* Obtain an cart ID to work with the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return: The cart identifier
*/
protected String obtainCartId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get("DefaultCartId"),
"Cart Id",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the cart ID" : promptMessage,
"The cart ID can't be empty");
}
/**
* Obtains a catalogItemId to work with from the configuration if set there or prompts the user to enter it.
*
* @return The catalog Item ID.
*/
protected String obtainCatalogItemId()
{
return this.obtainCatalogItemId(null);
}
/**
* Obtains a catalogItemId to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return The catalog Item ID.
*/
protected String obtainCatalogItemId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get( "DefaultCatalogItemId" ),
"Catalog Item Id", StringHelper.isNullOrWhiteSpace( promptMessage )
? "Enter the catalog item ID" : promptMessage,
"The catalog item ID can't be empty" );
}
/**
* Obtains a configuration policy ID to work with from the configuration if set there or prompts the user to enter it.
*
* @return A configuration policy ID.
*/
protected String obtainConfigurationPolicyId()
{
return this.obtainConfigurationPolicyId(null);
}
/**
* Obtains a configuration policy ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return A configuration policy ID.
*/
protected String obtainConfigurationPolicyId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get( "DefaultConfigurationPolicyId" ),
"Configuration Policy Id",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the configuration policy ID" : promptMessage,
"The configuration policy ID can't be empty");
}
/**
* Obtains a customer ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return A customer ID.
*/
protected String obtainCustomerId()
{
return this.obtainCustomerId( null );
}
protected String obtainCustomerId( String promptMessage )
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get( "DefaultCustomerId" ),
"Customer Id",
StringHelper.isNullOrWhiteSpace( promptMessage ) ? "Enter the customer ID" : promptMessage,
"The customer ID can't be empty" );
}
/**
* Obtains a customer ID to work with for Usage scenarios from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return A customer ID.
*/
protected String obtainCustomerIdForUsage( String promptMessage )
{
return this.obtainValue( this.getContext().getConfiguration().getScenarioSettings().get( "DefaultCustomerIdForUsage" ),
"Customer Id", StringHelper.isNullOrWhiteSpace( promptMessage )
? "Enter the customer ID" : promptMessage,
"The customer ID can't be empty" );
}
/**
* Obtains a customer user ID to work with from the configuration if set there or prompts the user to enter it.
*
* @return A customer ID.
*/
protected String obtainCustomerUserId()
{
return this.obtainCustomerUserId( null );
}
/**
* Obtains a customer user ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return A customer ID.
*/
protected String obtainCustomerUserId( String promptMessage )
{
return this.obtainValue( this.getContext().getConfiguration().getScenarioSettings().get( "DefaultCustomerUserId" ),
"Customer User Id", StringHelper.isNullOrWhiteSpace( promptMessage )
? "Enter the customer user ID" : promptMessage,
"The customer user ID can't be empty" );
}
/**
* Obtains a device ID to work with from the configuration if set there or prompts the user to enter it.
*
* @return A device ID.
*/
protected String obtainDeviceId()
{
return this.obtainDeviceId(null);
}
/**
* Obtains a device ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return A device ID.
*/
protected String obtainDeviceId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get( "DefaultDeviceId" ),
"Device Id",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the device ID" : promptMessage,
"The device ID can't be empty");
}
/**
* Obtains a device batch ID to work with from the configuration if set there or prompts the user to enter it.
*
* @return A device batch ID.
*/
protected String obtainDeviceBatchId()
{
return this.obtainDeviceBatchId(null);
}
/**
* Obtains a device batch ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return A device batch ID.
*/
protected String obtainDeviceBatchId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get( "DefaultDeviceBatchId" ),
"Device Batch Id",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the device batch ID" : promptMessage,
"The device batch ID can't be empty");
}
/**
* Obtains a directory role ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return A customer ID.
*/
protected String obtainDirectoryRoleId()
{
return this.obtainDirectoryRoleId( null );
}
protected String obtainDirectoryRoleId( String promptMessage )
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get( "DefaultDirectoryRoleId" ),
"Directory Role Id",
StringHelper.isNullOrWhiteSpace( promptMessage ) ? "Enter the Directory Role ID" : promptMessage,
"The Directory Role ID can't be empty" );
}
/***
* Obtains an indirect reseller ID to work with from the configuration if set there or prompts the user to enter it.
* @param promptMessage An optional custom prompt message.
* @return An indirect reseller ID.
*/
protected String obtainIndirectResellerId()
{
return this.obtainIndirectResellerId( null );
}
protected String obtainIndirectResellerId( String promptMessage )
{
return this.obtainValue( this.getContext().getConfiguration().getScenarioSettings().get( "DefaultIndirectResellerId" ),
"Indirect Reseller Id", StringHelper.isNullOrWhiteSpace( promptMessage )
? "Enter the indirect reseller ID" : promptMessage,
"The indirect reseller ID can't be empty" );
}
/**
* Obtains an MPN ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return The MPN ID.
*/
protected String obtainMpnId()
{
return this.obtainMpnId( null );
}
protected String obtainMpnId( String promptMessage )
{
return this.obtainValue( this.getContext().getConfiguration().getScenarioSettings().get( "PartnerMpnId" ),
"MPN Id",
StringHelper.isNullOrWhiteSpace( promptMessage ) ? "Enter the MPN ID" : promptMessage,
"The MPN ID can't be empty" );
}
/**
* Obtains an offer ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return The offer ID.
*/
protected String obtainOfferId( String promptMessage )
{
return this.obtainValue( this.getContext().getConfiguration().getScenarioSettings().get( "DefaultOfferId" ),
"Offer Id", StringHelper.isNullOrWhiteSpace( promptMessage ) ? "Enter the offer ID"
: promptMessage,
"The Offer ID can't be empty" );
}
/**
* Obtains an order ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return The offer ID.
*/
protected String obtainOrderId( String promptMessage )
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get("DefaultOrderId"),
"Order Id", StringHelper.isNullOrWhiteSpace( promptMessage ) ? "Enter the order ID" : promptMessage,
"The Order ID can't be empty" );
}
/**
* Obtains a product ID to work with from the configuration if set there or prompts the user to enter it.
*
* @return The product ID.
*/
protected String obtainProductId()
{
return this.obtainProductId(null);
}
/**
* Obtains a product ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return The product ID.
*/
protected String obtainProductId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get("DefaultProductId"),
"Product Id",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the product ID" : promptMessage,
"The Product ID can't be empty");
}
/**
* Obtain a quantity to update order with the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return: The quantity to update
*/
protected String obtainQuantity()
{
return this.obtainQuantity(null);
}
/**
* Obtain a quantity to update order with the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return: The quantity to update
*/
protected String obtainQuantity(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get("DefaultQuantity"),
"Quantity",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the Quantity" : promptMessage,
"The Quantity can't be empty");
}
/**
* Obtains a scope for probisioning status to work with from the configuration if set there or prompts the user to enter it.
*
* @return: The scope
*/
protected String obtainScope()
{
return this.obtainScope(null);
}
/**
* Obtains a scope for probisioning status to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return: The scope.
*/
protected String obtainScope(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get("DefaultScope"),
"Scope",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the Scope" : promptMessage,
"The Scope can't be empty");
}
/**
* Obtains a SKU ID to work with from the configuration if set there or prompts the user to enter it.
*
* @return: The SKU identifier.
*/
protected String obtainSkuId()
{
return this.obtainSkuId(null);
}
/**
* Obtains a SKU ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param promptMessage An optional custom prompt message.
* @return: The SKU identifier.
*/
protected String obtainSkuId(String promptMessage)
{
return this.obtainValue(
this.getContext().getConfiguration().getScenarioSettings().get("DefaultSkuId"),
"Sku Id",
StringHelper.isNullOrWhiteSpace(promptMessage) ? "Enter the sku ID" : promptMessage,
"The Sku ID can't be empty");
}
/**
* Obtains an subscription ID to work with from the configuration if set there or prompts the user to enter it.
*
* @param customerId The customer ID who owns the subscription.
* @param promptMessage An optional custom prompt message.
* @return The subscription ID.
*/
protected String obtainSubscriptionId( String customerId, String promptMessage )
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String subscriptionId =
this.getContext().getConfiguration().getScenarioSettings().get( "DefaultSubscriptionId" );
if ( StringHelper.isNullOrWhiteSpace( subscriptionId ) )
{
// get the customer subscriptions and let the user enter the subscription Id afterwards
System.out.println( "Retrieving customer subscriptions... " );
ResourceCollection<Subscription> subscriptions =
partnerOperations.getCustomers().byId( customerId ).getSubscriptions().get();
System.out.println( "Done!" );
this.getContext().getConsoleHelper().writeObject( subscriptions, "Customer subscriptions" );
System.out.println();
subscriptionId =
this.getContext().getConsoleHelper().readNonEmptyString( StringHelper.isNullOrWhiteSpace( promptMessage )
? "Enter the subscription ID" : promptMessage, "Subscription ID can't be empty" );
}
else
{
System.out.println( MessageFormat.format( "Found subscription ID: {0} in configuration.",
subscriptionId ) );
}
return subscriptionId;
}
/**
* Obtains an subscription ID to work with from the configuration for usage demo if set there or prompts the user to enter it.
*
* @param customerId The customer ID who owns the subscription.
* @param promptMessage An optional custom prompt message.
* @return The subscription ID.
*/
protected String obtainSubscriptionIdForUsage( String customerId, String promptMessage )
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String subscriptionId =
this.getContext().getConfiguration().getScenarioSettings().get( "DefaultSubscriptionIdForUsage" );
if ( StringHelper.isNullOrWhiteSpace( subscriptionId ) )
{
// get the customer subscriptions and let the user enter the subscription Id afterwards
System.out.println( "Retrieving customer subscriptions... " );
ResourceCollection<Subscription> subscriptions =
partnerOperations.getCustomers().byId( customerId ).getSubscriptions().get();
System.out.println( "Done!" );
this.getContext().getConsoleHelper().writeObject( subscriptions, "Customer subscriptions" );
System.out.println();
subscriptionId =
this.getContext().getConsoleHelper().readNonEmptyString( StringHelper.isNullOrWhiteSpace( promptMessage )
? "Enter the subscription ID" : promptMessage, "Subscription ID can't be empty" );
}
else
{
System.out.println( MessageFormat.format( "Found subscription ID: {0} in configuration.",
subscriptionId ) );
}
return subscriptionId;
}
/**
* Runs the scenario logic. This is delegated to the implementing sub class.
*/
protected abstract void runScenario();
/**
* Obtains a value to work with from the configuration if set there or prompts the user to enter it.
*
* @param configuredValue The value read from the configuration.
* @param title The title of the value.
* @param promptMessage The prompt message to use if the value was not set in the configuration.
* @param errorMessage The error message to use if the user did not enter a value.
* @return A string value.
*/
private String obtainValue( String configuredValue, String title, String promptMessage, String errorMessage )
{
String value = configuredValue;
if ( StringHelper.isNullOrWhiteSpace( value ) )
{
// The value was not set in the configuration, prompt the user the enter value
value = this.getContext().getConsoleHelper().readNonEmptyString( promptMessage, errorMessage );
}
else
{
System.out.println( MessageFormat.format( "Found {0}: {1} in configuration.", title, value ) );
}
return value;
}
}

Просмотреть файл

@ -0,0 +1,36 @@
// -----------------------------------------------------------------------
// <copyright file="IPartnerScenario.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples;
import java.util.List;
/**
* Represents a partner scenario that demos one or more related partner center APIs.
*/
public interface IPartnerScenario
{
/**
* Gets the scenario title.
*/
String getTitle();
/**
* Gets the children scenarios of the current scenario.
*/
List<IPartnerScenario> getChildren();
/**
* Gets the scenario context.
*/
IScenarioContext getContext();
/**
* Runs the scenario.
*/
void run();
}

Просмотреть файл

@ -0,0 +1,38 @@
// -----------------------------------------------------------------------
// <copyright file="IScenarioContext.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.samples.configuration.Configuration;
import com.microsoft.store.partnercenter.samples.helpers.ConsoleHelper;
/**
* Holds context properties useful to the scenarios.
*/
public interface IScenarioContext
{
/**
* Gets a partner operations instance which is user based authenticated.
*/
IAggregatePartner getUserPartnerOperations();
/**
* Gets a partner operations instance which is application based authenticated.
*/
IAggregatePartner getAppPartnerOperations();
/**
* Gets a configuration instance.
*/
Configuration getConfiguration();
/**
* Gets a console helper instance.
*/
ConsoleHelper getConsoleHelper();
}

Просмотреть файл

@ -0,0 +1,676 @@
// -----------------------------------------------------------------------
// <copyright file="Program.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.models.customers.CustomerSearchField;
import com.microsoft.store.partnercenter.samples.agreements.CreateCustomerAgreement;
import com.microsoft.store.partnercenter.samples.agreements.GetAgreementDetails;
import com.microsoft.store.partnercenter.samples.agreements.GetCustomerAgreements;
import com.microsoft.store.partnercenter.samples.analytics.GetPartnerLicensesDeploymentAnalytics;
import com.microsoft.store.partnercenter.samples.analytics.GetPartnerLicensesUsageAnalytics;
import com.microsoft.store.partnercenter.samples.analytics.GetCustomerLicensesDeploymentAnalytics;
import com.microsoft.store.partnercenter.samples.analytics.GetCustomerLicensesUsageAnalytics;
import com.microsoft.store.partnercenter.samples.auditrecords.GetAuditRecords;
import com.microsoft.store.partnercenter.samples.auditrecords.SearchAuditRecords;
import com.microsoft.store.partnercenter.samples.carts.CreateCart;
import com.microsoft.store.partnercenter.samples.carts.UpdateCart;
import com.microsoft.store.partnercenter.samples.carts.CheckoutCart;
import com.microsoft.store.partnercenter.samples.context.ScenarioContext;
import com.microsoft.store.partnercenter.samples.customerdirectoryroles.AddUserMemberToDirectoryRole;
import com.microsoft.store.partnercenter.samples.customerdirectoryroles.GetCustomerDirectoryRoleUserMembers;
import com.microsoft.store.partnercenter.samples.customerdirectoryroles.GetCustomerDirectoryRoles;
import com.microsoft.store.partnercenter.samples.customerdirectoryroles.RemoveCustomerUserMemberFromDirectoryRole;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerProducts;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerProductsByTargetSegment;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerProduct;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerSkus;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerSkusByTargetSegment;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerSku;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerSkuDownloadOptions;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerAvailabilities;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerAvailabilitiesByTargetSegment;
import com.microsoft.store.partnercenter.samples.customerproducts.GetCustomerAvailability;
import com.microsoft.store.partnercenter.samples.customers.CheckDomainAvailability;
import com.microsoft.store.partnercenter.samples.customers.CreateCustomer;
import com.microsoft.store.partnercenter.samples.customers.DeleteCustomerFromTipAccount;
import com.microsoft.store.partnercenter.samples.customers.FilterCustomers;
import com.microsoft.store.partnercenter.samples.customers.GetCustomerDetails;
import com.microsoft.store.partnercenter.samples.customers.GetCustomerManagedServices;
import com.microsoft.store.partnercenter.samples.customers.GetCustomerQualification;
import com.microsoft.store.partnercenter.samples.customers.GetCustomerRelationshipRequest;
import com.microsoft.store.partnercenter.samples.customers.GetPagedCustomers;
import com.microsoft.store.partnercenter.samples.customers.UpdateCustomerBillingProfile;
import com.microsoft.store.partnercenter.samples.customers.UpdateCustomerQualification;
import com.microsoft.store.partnercenter.samples.customers.ValidateCustomerAddress;
import com.microsoft.store.partnercenter.samples.customerservicecosts.GetCustomerServiceCostsLineItems;
import com.microsoft.store.partnercenter.samples.customerservicecosts.GetCustomerServiceCostsSummary;
import com.microsoft.store.partnercenter.samples.customersubscribedskus.CustomerSubscribedSkus;
import com.microsoft.store.partnercenter.samples.customerusers.CreateCustomerUser;
import com.microsoft.store.partnercenter.samples.customerusers.DeleteCustomerUser;
import com.microsoft.store.partnercenter.samples.customerusers.GetCustomerUserDetails;
import com.microsoft.store.partnercenter.samples.customerusers.UpdateCustomerUser;
import com.microsoft.store.partnercenter.samples.devicesdeployment.CreateConfigurationPolicy;
import com.microsoft.store.partnercenter.samples.devicesdeployment.GetAllConfigurationPolicies;
import com.microsoft.store.partnercenter.samples.devicesdeployment.UpdateConfigurationPolicy;
import com.microsoft.store.partnercenter.samples.devicesdeployment.DeleteConfigurationPolicy;
import com.microsoft.store.partnercenter.samples.devicesdeployment.CreateDeviceBatch;
import com.microsoft.store.partnercenter.samples.devicesdeployment.GetDevicesBatches;
import com.microsoft.store.partnercenter.samples.devicesdeployment.CreateDevices;
import com.microsoft.store.partnercenter.samples.devicesdeployment.GetDevices;
import com.microsoft.store.partnercenter.samples.devicesdeployment.UpdateDevicesPolicy;
import com.microsoft.store.partnercenter.samples.entitlements.GetEntitlements;
import com.microsoft.store.partnercenter.samples.devicesdeployment.DeleteDevice;
import com.microsoft.store.partnercenter.samples.devicesdeployment.GetBatchUploadStatus;
import com.microsoft.store.partnercenter.samples.customerusers.GetPagedCustomerUsers;
import com.microsoft.store.partnercenter.samples.customerusers.GetCustomerUserDirectoryRoles;
import com.microsoft.store.partnercenter.samples.customerusers.CustomerUserAssignedLicenses;
import com.microsoft.store.partnercenter.samples.customerusers.CustomerUserAssignedGroup1AndGroup2Licenses;
import com.microsoft.store.partnercenter.samples.customerusers.CustomerUserAssignedGroup1Licenses;
import com.microsoft.store.partnercenter.samples.customerusers.CustomerUserAssignedGroup2Licenses;
import com.microsoft.store.partnercenter.samples.customerusers.CustomerUserAssignLicenses;
import com.microsoft.store.partnercenter.samples.customerusers.CustomerUserAssignGroup1Licenses;
import com.microsoft.store.partnercenter.samples.customerusers.CustomerUserAssignGroup2Licenses;
import com.microsoft.store.partnercenter.samples.customerusers.GetCustomerInactiveUsers;
import com.microsoft.store.partnercenter.samples.customerusers.CustomerUserRestore;
import com.microsoft.store.partnercenter.samples.indirectmodel.CreateCustomerForIndirectReseller;
import com.microsoft.store.partnercenter.samples.indirectmodel.GetCustomersOfIndirectReseller;
import com.microsoft.store.partnercenter.samples.indirectmodel.GetIndirectResellers;
import com.microsoft.store.partnercenter.samples.indirectmodel.GetIndirectResellersOfCustomer;
import com.microsoft.store.partnercenter.samples.indirectmodel.GetSubscriptionsByMpnId;
import com.microsoft.store.partnercenter.samples.indirectmodel.PlaceOrderForCustomer;
import com.microsoft.store.partnercenter.samples.indirectmodel.VerifyPartnerMpnId;
import com.microsoft.store.partnercenter.samples.invoice.GetAccountBalance;
import com.microsoft.store.partnercenter.samples.invoice.GetInvoice;
import com.microsoft.store.partnercenter.samples.invoice.GetInvoiceLineItems;
import com.microsoft.store.partnercenter.samples.invoice.GetInvoiceStatement;
import com.microsoft.store.partnercenter.samples.invoice.GetInvoiceSummary;
import com.microsoft.store.partnercenter.samples.invoice.GetPagedInvoices;
import com.microsoft.store.partnercenter.samples.offers.GetCustomerOfferCategories;
import com.microsoft.store.partnercenter.samples.offers.GetCustomerOffers;
import com.microsoft.store.partnercenter.samples.offers.GetOffer;
import com.microsoft.store.partnercenter.samples.offers.GetOfferCategories;
import com.microsoft.store.partnercenter.samples.offers.GetOffers;
import com.microsoft.store.partnercenter.samples.offers.GetPagedOffers;
import com.microsoft.store.partnercenter.samples.orders.CreateAzureReservationOrder;
import com.microsoft.store.partnercenter.samples.orders.CreateOrder;
import com.microsoft.store.partnercenter.samples.orders.GetOrderDetails;
import com.microsoft.store.partnercenter.samples.orders.GetOrders;
import com.microsoft.store.partnercenter.samples.products.CheckInventory;
import com.microsoft.store.partnercenter.samples.products.GetAvailabilities;
import com.microsoft.store.partnercenter.samples.products.GetAvailabilitiesByTargetSegment;
import com.microsoft.store.partnercenter.samples.products.GetAvailability;
import com.microsoft.store.partnercenter.samples.products.GetProduct;
import com.microsoft.store.partnercenter.samples.products.GetProducts;
import com.microsoft.store.partnercenter.samples.products.GetProductsByTargetSegment;
import com.microsoft.store.partnercenter.samples.products.GetSku;
import com.microsoft.store.partnercenter.samples.products.GetSkuDownloadOptions;
import com.microsoft.store.partnercenter.samples.products.GetSkus;
import com.microsoft.store.partnercenter.samples.products.GetSkusByTargetSegment;
import com.microsoft.store.partnercenter.samples.profiles.GetBillingProfile;
import com.microsoft.store.partnercenter.samples.profiles.GetLegalBusinessProfile;
import com.microsoft.store.partnercenter.samples.profiles.GetMpnProfile;
import com.microsoft.store.partnercenter.samples.profiles.GetOrganizationProfile;
import com.microsoft.store.partnercenter.samples.profiles.GetSupportProfile;
import com.microsoft.store.partnercenter.samples.profiles.UpdateBillingProfile;
import com.microsoft.store.partnercenter.samples.profiles.UpdateLegalBusinessProfile;
import com.microsoft.store.partnercenter.samples.profiles.UpdateOrganizationProfile;
import com.microsoft.store.partnercenter.samples.profiles.UpdateSupportProfile;
import com.microsoft.store.partnercenter.samples.ratecards.GetAzureRateCard;
import com.microsoft.store.partnercenter.samples.ratecards.GetAzureSharedRateCard;
import com.microsoft.store.partnercenter.samples.ratedusage.GetCustomerSubscriptionsUsage;
import com.microsoft.store.partnercenter.samples.ratedusage.GetCustomerUsageSummary;
import com.microsoft.store.partnercenter.samples.ratedusage.GetSubscriptionUsageRecords;
import com.microsoft.store.partnercenter.samples.ratedusage.GetSubscriptionResourceUsage;
import com.microsoft.store.partnercenter.samples.ratedusage.GetSubscriptionUsageSummary;
import com.microsoft.store.partnercenter.samples.serviceincidents.GetServiceIncidents;
import com.microsoft.store.partnercenter.samples.servicerequests.CreatePartnerServiceRequest;
import com.microsoft.store.partnercenter.samples.servicerequests.GetAllCustomerServiceRequests;
import com.microsoft.store.partnercenter.samples.servicerequests.GetPagedPartnerServiceRequests;
import com.microsoft.store.partnercenter.samples.servicerequests.GetPartnerServiceRequestDetails;
import com.microsoft.store.partnercenter.samples.servicerequests.GetServiceRequestSupportTopics;
import com.microsoft.store.partnercenter.samples.servicerequests.UpdatePartnerServiceRequest;
import com.microsoft.store.partnercenter.samples.subscriptions.AddSubscriptionAddOn;
import com.microsoft.store.partnercenter.samples.subscriptions.GetSubscription;
import com.microsoft.store.partnercenter.samples.subscriptions.GetSubscriptions;
import com.microsoft.store.partnercenter.samples.subscriptions.GetSubscriptionsByOrder;
import com.microsoft.store.partnercenter.samples.subscriptions.UpdateSubscription;
import com.microsoft.store.partnercenter.samples.subscriptions.UpgradeSubscription;
import com.microsoft.store.partnercenter.samples.utilization.GetAzureSubscriptionUtilization;
import com.microsoft.store.partnercenter.samples.validations.AddressValidation;
/**
* The main program class for the partner center .NET SDK samples.
*/
public class Program
{
/**
* The main entry function.
*
* @param args Program arguments.
*/
public static void main( String[] args )
{
ScenarioContext context = new ScenarioContext();
List<IPartnerScenario> mainScenarios = new ArrayList<IPartnerScenario>();
mainScenarios.add( Program.getCustomerScenarios(context));
mainScenarios.add( Program.getAgreementsScenarios(context));
mainScenarios.add( Program.getOfferScenarios(context));
mainScenarios.add( Program.getProductScenarios(context));
mainScenarios.add( Program.getCustomerProductsScenarios(context));
mainScenarios.add( Program.getOrderScenarios(context));
mainScenarios.add( Program.getSubscriptionScenarios(context));
mainScenarios.add( Program.getRatedUsageScenarios(context));
mainScenarios.add( Program.getServiceRequestScenarios(context));
mainScenarios.add( Program.getInvoiceScenarios(context));
mainScenarios.add( Program.getProfileScenarios(context));
mainScenarios.add( Program.getCustomerUserScenarios(context));
mainScenarios.add( Program.getCustomerSubscribedSkusScenarios(context));
mainScenarios.add( Program.getCustomerDirectoryRoleScenarios(context));
mainScenarios.add( Program.getAuditRecordScenarios(context));
mainScenarios.add( Program.getRateCardScenarios(context));
mainScenarios.add( Program.getIndirectModelScenarios(context));
mainScenarios.add( Program.getServiceIncidentScenarios(context));
mainScenarios.add ( Program.getUtilizationScenarios(context));
mainScenarios.add( Program.getPartnerAnalyticsScenarios(context));
mainScenarios.add( Program.getCustomerServiceCostsScenarios(context));
mainScenarios.add(Program.getAddressValidationsScenarios(context));
mainScenarios.add( Program.getDevicesScenarios(context));
mainScenarios.add( Program.getCartScenarios(context));
mainScenarios.add( Program.getEntitlementScenarios(context));
// run the main scenario
new AggregatePartnerScenario( "Partner SDK samples", mainScenarios, context ).run();
}
/**
* Gets the customer scenarios.
*
* @param context A scenario context.
* @return The customer scenarios.
*/
private static IPartnerScenario getCustomerScenarios( IScenarioContext context )
{
List<IPartnerScenario> customerFilteringScenarios = new ArrayList<IPartnerScenario>();
customerFilteringScenarios.add( new FilterCustomers( "Filter by company name", CustomerSearchField.COMPANY_NAME,
context ) );
customerFilteringScenarios.add( new FilterCustomers( "Filter by domain name", CustomerSearchField.DOMAIN_NAME,
context ) );
List<IPartnerScenario> customerScenarios = new ArrayList<IPartnerScenario>();
customerScenarios.add( new CreateCustomer( context ) );
customerScenarios.add( new CheckDomainAvailability( context ) );
customerScenarios.add( new GetPagedCustomers(
context,
Integer.parseInt( context.getConfiguration().getScenarioSettings().get( "CustomerPageSize" ) ) ) );
customerScenarios.add( new AggregatePartnerScenario(
"Customer filtering", customerFilteringScenarios,
context ) );
customerScenarios.add( new GetCustomerDetails( context ) );
customerScenarios.add( new GetCustomerQualification( context ) );
customerScenarios.add( new UpdateCustomerQualification( context ) );
customerScenarios.add( new DeleteCustomerFromTipAccount( context ) );
customerScenarios.add( new GetCustomerManagedServices( context ) );
customerScenarios.add( new GetCustomerRelationshipRequest( context ) );
customerScenarios.add( new UpdateCustomerBillingProfile( context ) );
customerScenarios.add( new ValidateCustomerAddress( context ) );
return new AggregatePartnerScenario( "Customer samples", customerScenarios, context );
}
/**
* Gets the offer scenarios.
*
* @param context A scenario context.
* @return The offer scenarios.
*/
private static IPartnerScenario getOfferScenarios( IScenarioContext context )
{
List<IPartnerScenario> offerScenarios = new ArrayList<IPartnerScenario>();
offerScenarios.add( new GetOffer( context ) );
offerScenarios.add( new GetOfferCategories( context ) );
offerScenarios.add( new GetOffers( context ) );
offerScenarios.add( new GetPagedOffers( context ) );
offerScenarios.add( new GetCustomerOffers( context ) );
offerScenarios.add( new GetCustomerOfferCategories( context ) );
return new AggregatePartnerScenario( "Offer samples", offerScenarios, context );
}
/**
* Gets the order scenarios.
*
* @param context A scenario context.
* @return The order scenarios.
*/
private static IPartnerScenario getOrderScenarios( IScenarioContext context )
{
List<IPartnerScenario> orderScenarios = new ArrayList<IPartnerScenario>();
orderScenarios.add(new CreateOrder(context));
orderScenarios.add(new GetOrderDetails(context));
orderScenarios.add(new GetOrders(context));
orderScenarios.add(new CreateAzureReservationOrder(context));
return new AggregatePartnerScenario( "Order samples", orderScenarios, context );
}
/**
* Gets the subscription scenarios.
*
* @param context A scenario context.
* @return The subscription scenarios.
*/
private static IPartnerScenario getSubscriptionScenarios( IScenarioContext context )
{
List<IPartnerScenario> subscriptionScenarios = new ArrayList<IPartnerScenario>();
subscriptionScenarios.add( new GetSubscription( context ) );
subscriptionScenarios.add( new GetSubscriptions( context ) );
subscriptionScenarios.add( new GetSubscriptionsByOrder( context ) );
subscriptionScenarios.add( new UpdateSubscription( context ) );
subscriptionScenarios.add( new UpgradeSubscription( context ) );
subscriptionScenarios.add( new AddSubscriptionAddOn( context ) );
return new AggregatePartnerScenario( "Subscription samples", subscriptionScenarios, context );
}
/**
* Gets the subscription scenarios.
*
* @param context A scenario context.
* @return The subscription scenarios.
*/
private static IPartnerScenario getRatedUsageScenarios( IScenarioContext context )
{
List<IPartnerScenario> ratedUsageScenarios = new ArrayList<IPartnerScenario>();
ratedUsageScenarios.add( new GetCustomerUsageSummary( context ) );
ratedUsageScenarios.add( new GetCustomerSubscriptionsUsage( context ) );
ratedUsageScenarios.add( new GetSubscriptionResourceUsage( context ) );
ratedUsageScenarios.add( new GetSubscriptionUsageRecords( context ) );
ratedUsageScenarios.add( new GetSubscriptionUsageSummary( context ) );
return new AggregatePartnerScenario( "Rated Usage samples", ratedUsageScenarios, context );
}
/**
* Gets the service request scenarios.
*
* @param context A scenario context.
* @return The service request scenarios.
*/
private static IPartnerScenario getServiceRequestScenarios( IScenarioContext context )
{
List<IPartnerScenario> serviceRequestScenarios = new ArrayList<IPartnerScenario>();
serviceRequestScenarios.add( new CreatePartnerServiceRequest( context ) );
serviceRequestScenarios.add( new GetAllCustomerServiceRequests( context ) );
serviceRequestScenarios.add( new GetPagedPartnerServiceRequests( context,
Integer.parseInt( context.getConfiguration().getScenarioSettings().get( "ServiceRequestPageSize" ) ) ) );
serviceRequestScenarios.add( new GetPartnerServiceRequestDetails( context ) );
serviceRequestScenarios.add( new GetServiceRequestSupportTopics( context ) );
serviceRequestScenarios.add( new UpdatePartnerServiceRequest( context ) );
return new AggregatePartnerScenario( "Service request samples", serviceRequestScenarios, context );
}
/**
* Gets the invoice scenarios.
*
* @param context A scenario context.
* @return The invoice scenarios.
*/
private static IPartnerScenario getInvoiceScenarios( IScenarioContext context )
{
List<IPartnerScenario> invoiceScenarios = new ArrayList<IPartnerScenario>();
invoiceScenarios.add( new GetInvoiceSummary( context ) );
invoiceScenarios.add( new GetInvoice( context ) );
invoiceScenarios.add( new GetInvoiceLineItems(
context,
Integer.parseInt( context.getConfiguration().getScenarioSettings().get( "InvoicePageSize" ) ) ) );
invoiceScenarios.add( new GetPagedInvoices(
context,
Integer.parseInt( context.getConfiguration().getScenarioSettings().get( "InvoicePageSize" ) ) ) );
invoiceScenarios.add ( new GetAccountBalance( context ) );
invoiceScenarios.add ( new GetInvoiceStatement(context) );
return new AggregatePartnerScenario( "Invoice samples", invoiceScenarios, context );
}
/**
* Gets the Partner Profile scenarios.
*
* @param context A scenario context.
* @return The invoice scenarios.
*/
private static IPartnerScenario getProfileScenarios( IScenarioContext context )
{
List<IPartnerScenario> profileScenarios = new ArrayList<IPartnerScenario>();
profileScenarios.add( new GetBillingProfile( context ) );
profileScenarios.add( new GetLegalBusinessProfile( context ) );
profileScenarios.add( new GetOrganizationProfile( context ) );
profileScenarios.add( new GetMpnProfile( context ) );
profileScenarios.add( new GetSupportProfile( context ) );
profileScenarios.add( new UpdateBillingProfile( context ) );
profileScenarios.add( new UpdateLegalBusinessProfile( context ) );
profileScenarios.add( new UpdateOrganizationProfile( context ) );
profileScenarios.add( new UpdateSupportProfile( context ) );
return new AggregatePartnerScenario( "Partner Profile samples", profileScenarios, context );
}
/**
* Gets the Customer User scenarios.
*
* @param context A scenario context.
* @return The invoice scenarios.
*/
private static IPartnerScenario getCustomerUserScenarios( IScenarioContext context )
{
List<IPartnerScenario> customerUserScenarios = new ArrayList<IPartnerScenario>();
customerUserScenarios.add( new CreateCustomerUser( context ) );
customerUserScenarios.add( new DeleteCustomerUser ( context ) );
customerUserScenarios.add( new GetCustomerUserDetails( context ) );
customerUserScenarios.add( new UpdateCustomerUser( context ) );
customerUserScenarios.add( new GetPagedCustomerUsers ( context ) );
customerUserScenarios.add( new GetCustomerUserDirectoryRoles( context ) );
customerUserScenarios.add( new CustomerUserAssignedLicenses ( context ) );
customerUserScenarios.add( new CustomerUserAssignedGroup1AndGroup2Licenses( context ) );
customerUserScenarios.add( new CustomerUserAssignedGroup1Licenses ( context ) );
customerUserScenarios.add( new CustomerUserAssignedGroup2Licenses ( context ) );
customerUserScenarios.add( new CustomerUserAssignLicenses ( context ) );
customerUserScenarios.add( new CustomerUserAssignGroup1Licenses ( context ) );
customerUserScenarios.add( new CustomerUserAssignGroup2Licenses ( context ) );
customerUserScenarios.add( new GetCustomerInactiveUsers ( context ) );
customerUserScenarios.add( new CustomerUserRestore ( context ) );
return new AggregatePartnerScenario( "Customer User samples", customerUserScenarios, context );
}
/**
* Gets the customer subscribed skus scenarios.
*
* @param context A scenario context.
* @return The Customer subscribed skus scenarios.
*/
private static IPartnerScenario getCustomerSubscribedSkusScenarios( IScenarioContext context )
{
List<IPartnerScenario> customerSubscribedSkusScenarios = new ArrayList<IPartnerScenario>();
customerSubscribedSkusScenarios.add( new CustomerSubscribedSkus( context ) );
return new AggregatePartnerScenario( "Customer Subscribed Skus samples", customerSubscribedSkusScenarios, context );
}
/**
* Gets the customer directory role scenarios.
*
* @param context A scenario context.
* @return The directory role scenarios.
*/
private static IPartnerScenario getCustomerDirectoryRoleScenarios( IScenarioContext context )
{
List<IPartnerScenario> customerDirectoryRoleScenarios = new ArrayList<IPartnerScenario>();
customerDirectoryRoleScenarios.add( new GetCustomerDirectoryRoles( context ) );
customerDirectoryRoleScenarios.add( new AddUserMemberToDirectoryRole( context ) );
customerDirectoryRoleScenarios.add( new GetCustomerDirectoryRoleUserMembers( context ) );
customerDirectoryRoleScenarios.add( new RemoveCustomerUserMemberFromDirectoryRole( context ) );
return new AggregatePartnerScenario( "Customer Directory Role samples", customerDirectoryRoleScenarios, context );
}
/**
* Gets the Audit record scenarios.
*
* @param context A scenario context.
* @return The invoice scenarios.
*/
private static IPartnerScenario getAuditRecordScenarios( IScenarioContext context )
{
List<IPartnerScenario> auditRecordScenarios = new ArrayList<IPartnerScenario>();
auditRecordScenarios.add( new GetAuditRecords( context ) );
auditRecordScenarios.add( new SearchAuditRecords( context ) );
return new AggregatePartnerScenario( "Auditing samples", auditRecordScenarios, context );
}
/**
* Gets the rate card scenarios.
*
* @param context A scenario context.
* @return The rate card scenarios.
*/
private static IPartnerScenario getRateCardScenarios( IScenarioContext context )
{
List<IPartnerScenario> rateCardScenarios = new ArrayList<IPartnerScenario>();
rateCardScenarios.add( new GetAzureRateCard( context ) );
rateCardScenarios.add( new GetAzureSharedRateCard( context ));
return new AggregatePartnerScenario( "Rate Card samples", rateCardScenarios, context );
}
/**
* Gets the indirect model scenarios.
*
* @param context A scenario context.
* @return The invoice scenarios.
*/
private static IPartnerScenario getIndirectModelScenarios( IScenarioContext context )
{
List<IPartnerScenario> indirectModelScenarios = new ArrayList<IPartnerScenario>();
indirectModelScenarios.add( new GetIndirectResellers( context ) );
indirectModelScenarios.add( new CreateCustomerForIndirectReseller( context ) );
indirectModelScenarios.add( new GetIndirectResellersOfCustomer( context ) );
indirectModelScenarios.add( new PlaceOrderForCustomer( context ) );
indirectModelScenarios.add( new GetCustomersOfIndirectReseller( context ) );
indirectModelScenarios.add( new VerifyPartnerMpnId( context ) );
indirectModelScenarios.add( new GetSubscriptionsByMpnId( context ) );
return new AggregatePartnerScenario( "Indirect model samples", indirectModelScenarios, context );
}
/**
* Gets the Customer User scenarios.
*
* @param context A scenario context.
* @return The invoice scenarios.
*/
private static IPartnerScenario getServiceIncidentScenarios( IScenarioContext context )
{
List<IPartnerScenario> serviceIncidentScenarios = new ArrayList<IPartnerScenario>();
serviceIncidentScenarios.add( new GetServiceIncidents( context ) );
return new AggregatePartnerScenario( "Service Incident samples", serviceIncidentScenarios, context );
}
/**
* Gets the partner analytics scenarios..
*
* @param context A scenario context.
* @return The Partner Analytics scenarios
*/
private static IPartnerScenario getPartnerAnalyticsScenarios(IScenarioContext context)
{
List<IPartnerScenario> partnerAnalyticsScenarios = new ArrayList<IPartnerScenario>();
partnerAnalyticsScenarios.add( new GetPartnerLicensesDeploymentAnalytics( context ) );
partnerAnalyticsScenarios.add( new GetPartnerLicensesUsageAnalytics( context ) );
partnerAnalyticsScenarios.add( new GetCustomerLicensesDeploymentAnalytics( context ) );
partnerAnalyticsScenarios.add( new GetCustomerLicensesUsageAnalytics( context ) );
return new AggregatePartnerScenario( "Partner Analytics samples", partnerAnalyticsScenarios , context );
}
/**
* Gets the partner analytics scenarios.
*
* @param context A scenario context.
* @return The Partner Analytics scenarios
*/
private static IPartnerScenario getCustomerProductsScenarios(IScenarioContext context)
{
List<IPartnerScenario> customerProductsScenarios = new ArrayList<IPartnerScenario>();
customerProductsScenarios.add( new GetCustomerProducts( context ) );
customerProductsScenarios.add( new GetCustomerProductsByTargetSegment( context ) );
customerProductsScenarios.add( new GetCustomerProduct( context ) );
customerProductsScenarios.add( new GetCustomerSkus( context ) );
customerProductsScenarios.add( new GetCustomerSkusByTargetSegment( context ) );
customerProductsScenarios.add( new GetCustomerSku( context ) );
customerProductsScenarios.add( new GetCustomerSkuDownloadOptions( context ) );
customerProductsScenarios.add( new GetCustomerAvailabilities( context ) );
customerProductsScenarios.add( new GetCustomerAvailabilitiesByTargetSegment( context ) );
customerProductsScenarios.add( new GetCustomerAvailability( context ) );
return new AggregatePartnerScenario( "Products for customers samples", customerProductsScenarios, context );
}
/**
* Gets the cart scenarios of create, update and checkout
*
* @param context A scenario context.
* @return The cart scenarios.
*/
private static IPartnerScenario getCartScenarios(IScenarioContext context)
{
List<IPartnerScenario> cartScenarios = new ArrayList<IPartnerScenario>();
cartScenarios.add( new CreateCart( context ) );
cartScenarios.add( new UpdateCart( context ) );
cartScenarios.add( new CheckoutCart( context ) );
return new AggregatePartnerScenario( "Cart Scenarios", cartScenarios, context );
}
/**
* Gets the customer service costs scenarios.
*
* @param context A scenario context.
* @return The customer service costs scenarios.
*/
private static IPartnerScenario getCustomerServiceCostsScenarios(IScenarioContext context)
{
List<IPartnerScenario> customerServiceCostsScenarios = new ArrayList<IPartnerScenario>();
customerServiceCostsScenarios.add(new GetCustomerServiceCostsSummary(context));
customerServiceCostsScenarios.add(new GetCustomerServiceCostsLineItems(context));
return new AggregatePartnerScenario( "Customer service costs samples", customerServiceCostsScenarios, context );
}
/**
* Gets the Devices scenarios.
*
* @param context A scenario context.
* @return The Devices scenarios.
*/
private static IPartnerScenario getDevicesScenarios(ScenarioContext context)
{
List<IPartnerScenario> devicesScenarios = new ArrayList<IPartnerScenario>();
devicesScenarios.add(new CreateConfigurationPolicy(context));
devicesScenarios.add(new GetAllConfigurationPolicies(context));
devicesScenarios.add(new UpdateConfigurationPolicy(context));
devicesScenarios.add(new DeleteConfigurationPolicy(context));
devicesScenarios.add(new CreateDeviceBatch(context));
devicesScenarios.add(new GetDevicesBatches(context));
devicesScenarios.add(new CreateDevices(context));
devicesScenarios.add(new GetDevices(context));
devicesScenarios.add(new UpdateDevicesPolicy(context));
devicesScenarios.add(new DeleteDevice(context));
devicesScenarios.add(new GetBatchUploadStatus(context));
return new AggregatePartnerScenario( "Devices", devicesScenarios, context );
}
/**
* Gets the Entitlement scenarios.
*
* @param context A scenario context.
* @return The Entitlement scenarios.
*/
private static IPartnerScenario getEntitlementScenarios(ScenarioContext context)
{
List<IPartnerScenario> entitlementScenarios = new ArrayList<IPartnerScenario>();
entitlementScenarios.add(new GetEntitlements(context) );
return new AggregatePartnerScenario( "Entitlements", entitlementScenarios, context );
}
/**
* Gets the Utilization scenarios.
*
* @param context A scenario context.
* @return The Utilization scenarios.
*/
private static IPartnerScenario getUtilizationScenarios(ScenarioContext context)
{
List<IPartnerScenario> utilizationScnearios = new ArrayList<IPartnerScenario>();
utilizationScnearios.add(new GetAzureSubscriptionUtilization(context));
return new AggregatePartnerScenario( "Utilization samples", utilizationScnearios, context );
}
/**
* Gets the product scenarios.
*
* @param context A scenario context.
* @return The product scenarios
*/
private static IPartnerScenario getProductScenarios(IScenarioContext context)
{
List<IPartnerScenario> productScenarios = new ArrayList<IPartnerScenario>();
productScenarios.add(new CheckInventory(context));
productScenarios.add(new GetAvailabilities(context));
productScenarios.add(new GetAvailabilitiesByTargetSegment(context));
productScenarios.add(new GetAvailability(context));
productScenarios.add(new GetProduct(context));
productScenarios.add(new GetProducts(context));
productScenarios.add(new GetProductsByTargetSegment(context));
productScenarios.add(new GetSku(context));
productScenarios.add(new GetSkuDownloadOptions(context));
productScenarios.add(new GetSkusByTargetSegment(context));
productScenarios.add(new GetSkus(context));
return new AggregatePartnerScenario( "Product samples", productScenarios, context );
}
/**
* Gets the address validation scenarios.
*
* @param context A scenario context.
* @return The address validation scenarios.
*/
private static IPartnerScenario getAddressValidationsScenarios(IScenarioContext context)
{
List<IPartnerScenario> addressValidationScenarios = new ArrayList<IPartnerScenario>();
addressValidationScenarios.add(new AddressValidation(context));
return new AggregatePartnerScenario( "Address validation samples", addressValidationScenarios, context );
}
/**
* Gets the agreements scenarios.
*
* @param context A scenario context.
* @return The agreements scenarios.
*/
private static IPartnerScenario getAgreementsScenarios(IScenarioContext context)
{
List<IPartnerScenario> agreementsScenario = new ArrayList<IPartnerScenario>();
agreementsScenario.add(new GetAgreementDetails(context));
agreementsScenario.add(new GetCustomerAgreements(context));
agreementsScenario.add(new CreateCustomerAgreement(context));
return new AggregatePartnerScenario( "Agreements", agreementsScenario, context );
}
}

Просмотреть файл

@ -0,0 +1,85 @@
// -----------------------------------------------------------------------
// <copyright file="CreateCustomerAgreement.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.agreements;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.Contact;
import com.microsoft.store.partnercenter.models.agreements.Agreement;
import com.microsoft.store.partnercenter.models.agreements.AgreementType;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
import com.microsoft.store.partnercenter.utils.StringHelper;
import org.joda.time.DateTime;
/**
* Showcases creation of a customer agreement.
*/
public class CreateCustomerAgreement
extends BasePartnerScenario
{
public CreateCustomerAgreement (IScenarioContext context)
{
super("Create a new customer agreement", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String selectedCustomerId = this.obtainCustomerId("Enter the ID of the customer to create the agreement for");
String selectedUserId = this.obtainCustomerUserId("Enter the user ID of the partner to create customer's agreement");
String agreementTemplateId = this.getContext().getConfiguration().getScenarioSettings().get("DefaultAgreementTemplateId");
// Currently, the only supported value is 998b88de-aa99-4388-a42c-1b3517d49490, which is the unique identifier for the Microsoft Cloud Agreement.
if ( StringHelper.isNullOrWhiteSpace( agreementTemplateId ) )
{
// The value was not set in the configuration, prompt the user the enter value
agreementTemplateId =
this.getContext().getConsoleHelper().readNonEmptyString(
"Enter the agreement template ID", "The agreement template ID can't be empty");
}
else
{
System.out.println(
MessageFormat.format(
"Found agreement template ID: {0} in configuration.",
agreementTemplateId ) );
}
Contact contact = new Contact();
contact.setEmail("first.last@outlook.com");
contact.setFirstName("First");
contact.setLastName("Last");
contact.setPhoneNumber("4255555555");
Agreement agreement = new Agreement();
agreement.setDateAgreed(new DateTime());
agreement.setPrimaryContact(contact);
agreement.setTemplateId(agreementTemplateId);
agreement.setType(AgreementType.MICROSOFT_CLOUD_AGREEMENT);
agreement.setUserId(selectedUserId);
this.getContext().getConsoleHelper().writeObject(agreement, "New Agreement");
this.getContext().getConsoleHelper().startProgress("Creating Agreement");
Agreement newlyCreatedagreement = partnerOperations.getCustomers().byId(selectedCustomerId).getAgreements().create(agreement);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success("Create new agreement successfully!");
this.getContext().getConsoleHelper().writeObject(newlyCreatedagreement, "Newly created agreement Information");
}
}

Просмотреть файл

@ -0,0 +1,42 @@
// -----------------------------------------------------------------------
// <copyright file="GetAgreementDetails.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.agreements;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.agreements.AgreementMetaData;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Showcases getting the list of agreement details.
*/
public class GetAgreementDetails
extends BasePartnerScenario
{
public GetAgreementDetails (IScenarioContext context)
{
super("Get agreement details", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Retrieving agreement details" );
ResourceCollection<AgreementMetaData> agreementDetails = partnerOperations.getAgreementDetails().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( agreementDetails, "Agreement details:" );
}
}

Просмотреть файл

@ -0,0 +1,43 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerAgreements.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.agreements;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.agreements.Agreement;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Showcases getting the list of agreement details.
*/
public class GetCustomerAgreements
extends BasePartnerScenario
{
public GetCustomerAgreements (IScenarioContext context)
{
super("Get all customer agreements", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String selectedCustomerId = this.obtainCustomerId( "Enter the ID of the customer" );
this.getContext().getConsoleHelper().startProgress( "Retrieving the customer's agreements" );
ResourceCollection<Agreement> customerAgreements = partnerOperations.getCustomers().byId(selectedCustomerId).getAgreements().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( customerAgreements, "Customer agreements:" );
}
}

Просмотреть файл

@ -0,0 +1,43 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerLicensesDeploymentAnalytics .java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.analytics;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.analytics.CustomerLicensesDeploymentInsights;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets a single customer's licenses deployment analytics.
*/
public class GetCustomerLicensesDeploymentAnalytics extends BasePartnerScenario
{
public GetCustomerLicensesDeploymentAnalytics (IScenarioContext context)
{
super("Get customer licenses deployment analytics", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerIdToRetrieve = this.obtainCustomerId( "Enter the ID of the customer to retrieve" );
this.getContext().getConsoleHelper().startProgress( "Retrieving customer licenses deployment analytics" );
ResourceCollection<CustomerLicensesDeploymentInsights> customerLicensesDeploymentAnalytics =
partnerOperations.getCustomers().byId(customerIdToRetrieve).getAnalytics().getLicenses().getDeployment().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( customerLicensesDeploymentAnalytics, "Customer licenses deployment analytics" );
}
}

Просмотреть файл

@ -0,0 +1,43 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerLicensesUsageAnalytics .java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.analytics;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.analytics.CustomerLicensesUsageInsights;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets a single customer's licenses usage analytics.
*/
public class GetCustomerLicensesUsageAnalytics extends BasePartnerScenario
{
public GetCustomerLicensesUsageAnalytics (IScenarioContext context)
{
super("Get customer licenses usage analytics", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerIdToRetrieve = this.obtainCustomerId( "Enter the ID of the customer to retrieve" );
this.getContext().getConsoleHelper().startProgress( "Retrieving customer licenses usage analytics" );
ResourceCollection<CustomerLicensesUsageInsights> customerLicensesDeploymentAnalytics =
partnerOperations.getCustomers().byId(customerIdToRetrieve).getAnalytics().getLicenses().getUsage().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( customerLicensesDeploymentAnalytics, "Customer licenses usage analytics" );
}
}

Просмотреть файл

@ -0,0 +1,41 @@
// -----------------------------------------------------------------------
// <copyright file="GetPartnerLicensesDeploymentAnalytics.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.analytics;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.analytics.PartnerLicensesDeploymentInsights;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets partner's licenses deployment analytics.
*/
public class GetPartnerLicensesDeploymentAnalytics extends BasePartnerScenario
{
public GetPartnerLicensesDeploymentAnalytics (IScenarioContext context)
{
super("Get partner licenses deployment analytics", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Retrieving partner licenses deployment analytics" );
ResourceCollection<PartnerLicensesDeploymentInsights> partnerLicensesDeploymentAnalytics =
partnerOperations.getAnalytics().getLicenses().getDeployment().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( partnerLicensesDeploymentAnalytics, "Partner licenses deployment analytics" );
}
}

Просмотреть файл

@ -0,0 +1,41 @@
// -----------------------------------------------------------------------
// <copyright file="GetPartnerLicensesUsageAnalytics.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.analytics;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.analytics.PartnerLicensesUsageInsights;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets partner's licenses usage analytics.
*/
public class GetPartnerLicensesUsageAnalytics extends BasePartnerScenario
{
public GetPartnerLicensesUsageAnalytics (IScenarioContext context)
{
super("Get partner licenses usage analytics", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Retrieving partner licenses usage analytics" );
ResourceCollection<PartnerLicensesUsageInsights> partnerLicensesUsageAnalytics =
partnerOperations.getAnalytics().getLicenses().getUsage().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( partnerLicensesUsageAnalytics, "Partner licenses usage analytics" );
}
}

Просмотреть файл

@ -0,0 +1,81 @@
// -----------------------------------------------------------------------
// <copyright file="GetAuditRecords.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.auditrecords;
import java.util.Iterator;
import org.joda.time.DateTime;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.enumerators.IResourceCollectionEnumerator;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.auditing.AuditRecord;
import com.microsoft.store.partnercenter.models.query.QueryFactory;
import com.microsoft.store.partnercenter.models.utils.KeyValuePair;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
public class GetAuditRecords extends BasePartnerScenario
{
public GetAuditRecords(IScenarioContext context) {
super("Query for the partner's audit records", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario() {
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Querying audit records" );
DateTime startDate = DateTime.now().minusDays(1);
// query the audit records, get the first page if a page size was set, otherwise get all customers
SeekBasedResourceCollection<AuditRecord> auditRecordsCollection =
partnerOperations.getAuditRecords().query(startDate, null, QueryFactory.getInstance().buildIndexedQuery( 10 ) );
this.getContext().getConsoleHelper().stopProgress();
// create an AuditRecord enumerator which will aid us in traversing the customer pages
IResourceCollectionEnumerator<SeekBasedResourceCollection<AuditRecord>> auditRecordssEnumerator =
partnerOperations.getEnumerators().getAuditRecords().create( auditRecordsCollection );
while ( auditRecordssEnumerator.hasValue() )
{
// print the current customer results page
System.out.println("Record count: " + auditRecordssEnumerator.getCurrent().getTotalCount());
for (AuditRecord record : auditRecordssEnumerator.getCurrent().getItems())
{
System.out.println("Customer Id: " + record.getCustomerId() );
System.out.println("Customer Name: " + record.getCustomerName() );
System.out.println("Resource Type: " + record.getResourceType() );
System.out.println("Date: " + record.getOperationDate().toString("yyyy-MM-dd") );
System.out.println("Operation Type: " + record.getOperationType() );
System.out.println("Status: " + record.getOperationStatus() );
System.out.println("User: " + record.getUserPrincipalName() );
System.out.println("Application: " + record.getApplicationId() );
System.out.println("New Value: " + record.getResourceNewValue() );
if (record.getCustomizedData()!=null && record.getCustomizedData().iterator()!=null)
{
Iterator<KeyValuePair<String,String>> customizedDataIterator = record.getCustomizedData().iterator();
System.out.println("Customized Data:");
KeyValuePair<String,String> currentPair = null;
while ( customizedDataIterator.hasNext() )
{
currentPair = customizedDataIterator.next();
System.out.println(" "+currentPair.getKey() +" : "+ currentPair.getValue() );
}
}
System.out.println();
}
System.out.println();
auditRecordssEnumerator.next();
}
}
}

Просмотреть файл

@ -0,0 +1,71 @@
// -----------------------------------------------------------------------
// <copyright file="SearchAuditRecords.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.auditrecords;
import org.joda.time.DateTime;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.enumerators.IResourceCollectionEnumerator;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.auditing.AuditRecord;
import com.microsoft.store.partnercenter.models.auditing.AuditRecordSearchField;
import com.microsoft.store.partnercenter.models.query.QueryFactory;
import com.microsoft.store.partnercenter.models.query.filters.FieldFilterOperation;
import com.microsoft.store.partnercenter.models.query.filters.SimpleFieldFilter;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
public class SearchAuditRecords extends BasePartnerScenario
{
public SearchAuditRecords(IScenarioContext context) {
super("Filter by company name", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario() {
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String companyName =
this.getContext().getConsoleHelper().readNonEmptyString(
"Enter the company name to filter by",
"The company name cannot be empty" );
this.getContext().getConsoleHelper().startProgress( "Searching Audit Records" );
DateTime startDate = new DateTime().dayOfMonth().withMinimumValue();
SimpleFieldFilter filter = new SimpleFieldFilter(AuditRecordSearchField.COMPANY_NAME.toString(), companyName, FieldFilterOperation.SUBSTRING );
SeekBasedResourceCollection<AuditRecord> auditRecordsCollection =
partnerOperations.getAuditRecords().query(startDate, null, QueryFactory.getInstance().buildSimpleQuery( filter ) );
this.getContext().getConsoleHelper().stopProgress();
IResourceCollectionEnumerator<SeekBasedResourceCollection<AuditRecord>> auditRecordssEnumerator =
partnerOperations.getEnumerators().getAuditRecords().create( auditRecordsCollection );
while ( auditRecordssEnumerator.hasValue() )
{
System.out.println("Record count: " + auditRecordssEnumerator.getCurrent().getTotalCount());
for (AuditRecord record : auditRecordssEnumerator.getCurrent().getItems())
{
System.out.println("Customer Id: " + record.getCustomerId() );
System.out.println("Customer Name: " + record.getCustomerName() );
System.out.println("Resource Type: " + record.getResourceType() );
System.out.println("Date: " + record.getOperationDate().toString("yyyy-MM-dd") );
System.out.println("Operation Type: " + record.getOperationType() );
System.out.println("Status: " + record.getOperationStatus() );
System.out.println("User: " + record.getUserPrincipalName() );
System.out.println("Application: " + record.getApplicationId() );
System.out.println("New Value: " + record.getResourceNewValue() );
System.out.println();
}
auditRecordssEnumerator.next();
}
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// -----------------------------------------------------------------------
// <copyright file="CheckoutCart.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.carts;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.carts.Cart;
import com.microsoft.store.partnercenter.models.carts.CartCheckoutResult;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that checkout a cart for a customer.
*/
public class CheckoutCart extends BasePartnerScenario
{
public CheckoutCart (IScenarioContext context)
{
super("Checkout a cart", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId( "Enter the ID of the customer making the purchase" );
String cartId = this.obtainCartId("Enter the ID of cart to checkout");
Cart existingCart = partnerOperations.getCustomers().byId(customerId).getCarts().byId(cartId).get();
this.getContext().getConsoleHelper().writeObject( existingCart, "Cart to be checked out" );
this.getContext().getConsoleHelper().startProgress("Checking out cart");
CartCheckoutResult checkoutResult = partnerOperations.getCustomers().byId(customerId).getCarts().byId(cartId).checkout();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( checkoutResult, "Final Cart: " );
}
}

Просмотреть файл

@ -0,0 +1,92 @@
// -----------------------------------------------------------------------
// <copyright file="CreateCart.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.carts;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.carts.Cart;
import com.microsoft.store.partnercenter.models.carts.CartLineItem;
import com.microsoft.store.partnercenter.models.products.Sku;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that creates a new cart for a customer.
*/
public class CreateCart extends BasePartnerScenario
{
public CreateCart (IScenarioContext context)
{
super("Create a cart", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer making the purchase" );
String catalogItemId = this.obtainCatalogItemId("Enter the catalog Item Id");
String productId = catalogItemId.split(":")[0];
String skuId = catalogItemId.split(":")[1];
String scope = "";
String subscriptionId = "";
String duration = "";
Sku sku = partnerOperations.getProducts().byCountry("US").byId(productId).getSkus().byId(skuId).get();
if (sku.getProvisioningVariables() != null)
{
scope = this.obtainScope("Enter the Scope for the Provisioning status");
subscriptionId = this.obtainAzureSubscriptionId("Enter the Subscription Id");
duration = sku.getDynamicAttributes().get("duration");
}
CartLineItem lineItem = new CartLineItem();
lineItem.setBillingCycle(sku.getSupportedBillingCycles().get(0));
lineItem.setCatalogItemId(catalogItemId);
lineItem.setFriendlyName("Myofferpurchase");
lineItem.setQuantity(1);
if(sku.getProvisioningVariables() == null)
{
lineItem.setProvisioningContext(null);
}
else
{
Map<String, String> provisioningContext = new HashMap<String,String>();
provisioningContext.put("duration", duration);
provisioningContext.put("scope", scope);
provisioningContext.put("subscriptionId", subscriptionId);
lineItem.setProvisioningContext(provisioningContext);
}
List<CartLineItem> lineItemList = new ArrayList<CartLineItem>();
lineItemList.add(lineItem);
Cart cart = new Cart();
cart.setLineItems(lineItemList);
this.getContext().getConsoleHelper().writeObject( cart, "Cart to be created" );
this.getContext().getConsoleHelper().startProgress( "Creating cart" );
Cart cartCreated = partnerOperations.getCustomers().byId(customerId).getCarts().create(cart);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( cartCreated, "Created cart" );
}
}

Просмотреть файл

@ -0,0 +1,50 @@
// -----------------------------------------------------------------------
// <copyright file="UpdateCart .java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.carts;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.carts.Cart;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that updates a cart for a customer.
*/
public class UpdateCart extends BasePartnerScenario
{
public UpdateCart (IScenarioContext context)
{
super("Update a Cart", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId( "Enter the ID of the customer making the purchase" );
String cartId = this.obtainCartId("Enter the ID of cart to be updated");
int quantityChange = Integer.parseInt(this.obtainQuantity("Enter the amount the quantity has to be changed"));
Cart existingCart = partnerOperations.getCustomers().byId(customerId).getCarts().byId(cartId).get();
this.getContext().getConsoleHelper().writeObject( existingCart, "Cart to be updated" );
this.getContext().getConsoleHelper().startProgress("Updating cart");
existingCart.getLineItems().get(0).setQuantity(
existingCart.getLineItems().get(0).getQuantity() + quantityChange
);
Cart updatedCart = partnerOperations.getCustomers().byId(customerId).getCarts().byId(cartId).put(existingCart);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(updatedCart, "Updated cart" );
}
}

Просмотреть файл

@ -0,0 +1,66 @@
// -----------------------------------------------------------------------
// <copyright file="Configuration.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.configuration;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Configuration
{
@JsonProperty( "PartnerServiceSettings" )
private Map<String, String> partnerServiceSettings;
public Map<String, String> getPartnerServiceSettings()
{
return partnerServiceSettings;
}
public void setPartnerServiceSettings( Map<String, String> partnerServiceSettings )
{
this.partnerServiceSettings = partnerServiceSettings;
}
@JsonProperty( "UserAuthentication" )
private Map<String, String> userAuthentication;
public Map<String, String> getUserAuthentication()
{
return userAuthentication;
}
public void setUserAuthentication( Map<String, String> userAuthentication )
{
this.userAuthentication = userAuthentication;
}
@JsonProperty( "AppAuthentication" )
private Map<String, String> appAuthentication;
public Map<String, String> getAppAuthentication()
{
return appAuthentication;
}
public void setAppAuthentication( Map<String, String> appAuthentication )
{
this.appAuthentication = appAuthentication;
}
@JsonProperty( "ScenarioSettings" )
private Map<String, String> scenarioSettings;
public Map<String, String> getScenarioSettings()
{
return scenarioSettings;
}
public void setScenarioSettings( Map<String, String> scenarioSettings )
{
this.scenarioSettings = scenarioSettings;
}
}

Просмотреть файл

@ -0,0 +1,51 @@
// -----------------------------------------------------------------------
// <copyright file="ConfigurationHolder.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.configuration;
import java.io.IOException;
import java.io.InputStream;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.microsoft.store.partnercenter.exception.PartnerException;
import com.microsoft.store.partnercenter.samples.Program;
public class ConfigurationHolder
{
public static Configuration configuration;
private static ConfigurationHolder instance;
private ConfigurationHolder()
{
ObjectMapper mapper = new ObjectMapper();
InputStream is = Program.class.getClassLoader().getResourceAsStream( "SamplesConfiguration.json" );
// System.out.println( StringHelper.fromInputStream(is, "UTF-8") );
try
{
configuration = mapper.readValue( is, Configuration.class );
}
catch ( IOException e )
{
throw new PartnerException( "Problem reading PartnerSDK Samples configuration file", e );
}
}
public static ConfigurationHolder getInstance()
{
if ( instance == null )
{
instance = new ConfigurationHolder();
}
return instance;
}
public Configuration getConfiguration()
{
return configuration;
}
}

Просмотреть файл

@ -0,0 +1,107 @@
// -----------------------------------------------------------------------
// <copyright file="ScenarioContext.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.context;
import com.microsoft.store.partnercenter.IAadLoginHandler;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.IPartnerCredentials;
import com.microsoft.store.partnercenter.PartnerService;
import com.microsoft.store.partnercenter.extensions.PartnerCredentials;
import com.microsoft.store.partnercenter.samples.AadUserLoginHandler;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
import com.microsoft.store.partnercenter.samples.configuration.Configuration;
import com.microsoft.store.partnercenter.samples.configuration.ConfigurationHolder;
import com.microsoft.store.partnercenter.samples.helpers.ConsoleHelper;
/**
* Scenario context implementation class.
*/
public class ScenarioContext
implements IScenarioContext
{
/**
* A lazy reference to an user based partner operations.
*/
private IAggregatePartner userPartnerOperations = null;
/**
* A lazy reference to an application based partner operations.
*/
private IAggregatePartner appPartnerOperations = null;
/**
* Initializes a new instance of the {@link #ScenarioContext} class.
*/
public ScenarioContext()
{
PartnerService.getInstance().setApiRootUrl( ConfigurationHolder.getInstance().getConfiguration().getPartnerServiceSettings().get( "PartnerServiceApiEndpoint" ) );
}
/**
* Gets a partner operations instance which is application based authenticated.
*/
@Override
public IAggregatePartner getAppPartnerOperations()
{
if ( this.appPartnerOperations == null )
{
System.out.println( "Authenticating application... " );
IPartnerCredentials appCredentials =
PartnerCredentials.getInstance().generateByApplicationCredentials( ConfigurationHolder.getInstance().getConfiguration().getAppAuthentication().get( "ApplicationId" ),
ConfigurationHolder.getInstance().getConfiguration().getAppAuthentication().get( "ApplicationSecret" ),
ConfigurationHolder.getInstance().getConfiguration().getAppAuthentication().get( "Domain" ),
ConfigurationHolder.getInstance().getConfiguration().getPartnerServiceSettings().get( "AuthenticationAuthorityEndpoint" ),
ConfigurationHolder.getInstance().getConfiguration().getPartnerServiceSettings().get( "GraphEndpoint" ) );
System.out.println( "Authenticated!" );
this.appPartnerOperations = PartnerService.getInstance().createPartnerOperations( appCredentials );
}
return this.appPartnerOperations;
}
/**
* Gets a configuration instance.
*/
@Override
public Configuration getConfiguration()
{
return ConfigurationHolder.getInstance().getConfiguration();
}
/**
* Gets a console helper instance.
*/
@Override
public ConsoleHelper getConsoleHelper()
{
return ConsoleHelper.getInstance();
}
/**
* Gets a partner operations instance which is user based authenticated.
*/
@Override
public IAggregatePartner getUserPartnerOperations()
{
if ( this.userPartnerOperations == null )
{
System.out.println( "Authenticating user... " );
// give the partner SDK the new add token information
IAadLoginHandler loginHandler = new AadUserLoginHandler();
IPartnerCredentials userCredentials =
PartnerCredentials.getInstance().generateByUserCredentials( this.getConfiguration().getUserAuthentication().get( "ClientId" ),
loginHandler.authenticate(), loginHandler );
System.out.println( "Authenticated!" );
this.userPartnerOperations = PartnerService.getInstance().createPartnerOperations( userCredentials );
}
return this.userPartnerOperations;
}
}

Просмотреть файл

@ -0,0 +1,83 @@
//-----------------------------------------------------------------------
//<copyright file="AddUserMemberToDirectoryRole.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
//</copyright>
//-----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerdirectoryroles;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.roles.DirectoryRole;
import com.microsoft.store.partnercenter.models.roles.UserMember;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets a single customer details.
*/
public class AddUserMemberToDirectoryRole
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetCustomerDetails} class.
*
* @param context The scenario context.
*/
public AddUserMemberToDirectoryRole( IScenarioContext context )
{
super( "Add customer user to a directory role", context );
}
/**
* Executes the get customer details scenario.
*/
@Override
protected void runScenario()
{
String customerId = this.obtainCustomerId( "Enter the ID of the customer to retrieve" );
String customerUserId = this.obtainCustomerUserId( "Enter the ID of the customer user to retrieve" );
String roleId = this.obtainDirectoryRoleId( "Enter the ID of the directory role to use" );
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the customer to create new user for" );
Customer selectedCustomer = partnerOperations.getCustomers().byId( customerId ).get();
// read the selected customer id from the application state.
String selectedCustomerId = selectedCustomer.getId();
this.getContext().getConsoleHelper().startProgress( "Getting user" );
CustomerUser customerUser = partnerOperations.getCustomers().byId(selectedCustomerId).getUsers().byId( customerUserId ).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success( "Success!" );
this.getContext().getConsoleHelper().writeObject( customerUser, "Customer user Information" );
// Read all directory roles to find the one we need to use.
DirectoryRole selectedRole = null;
Iterable<DirectoryRole> directoryRoles = partnerOperations.getCustomers().byId( customerId ).getDirectoryRoles().get().getItems();
for (DirectoryRole role : directoryRoles )
{
if( role.getId().equalsIgnoreCase( roleId ) )
{
selectedRole = role;
break;
}
}
UserMember userToAdd = new UserMember();
userToAdd.setUserPrincipalName( customerUser.getUserPrincipalName() );
userToAdd.setDisplayName( customerUser.getDisplayName() );
userToAdd.setId( customerUser.getId() );
// Add this customer user to the selected directory role.
this.getContext().getConsoleHelper().startProgress( "Adding user to Directory Role" );
UserMember userMemberAdded = partnerOperations.getCustomers().byId( selectedCustomerId ).getDirectoryRoles().byId( selectedRole.getId() ).getUserMembers().create( userToAdd );
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success( "Success!" );
this.getContext().getConsoleHelper().writeObject( userMemberAdded, "User Information after adding to Directory role " + selectedRole.getName() );
}
}

Просмотреть файл

@ -0,0 +1,50 @@
//-----------------------------------------------------------------------
//<copyright file="GetCustomerDirectoryRoleUserMembers.java" company="Microsoft">
//Copyright (c) Microsoft Corporation. All rights reserved.
//</copyright>
//-----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerdirectoryroles;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.roles.UserMember;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets a single customer details.
*/
public class GetCustomerDirectoryRoleUserMembers
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetCustomerDetails} class.
*
* @param context The scenario context.
*/
public GetCustomerDirectoryRoleUserMembers( IScenarioContext context )
{
super( "Get Customer Directory Role User Members", context );
}
/**
* Executes the get customer details scenario.
*/
@Override
protected void runScenario()
{
String customerId = this.obtainCustomerId( "Enter the ID of the customer to retrieve" );
String roleId = this.obtainDirectoryRoleId( "Enter the ID of the directory role to use" );
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the customer to create new user for" );
// Get all members having the selected directory role.
SeekBasedResourceCollection<UserMember> userMembers = partnerOperations.getCustomers().byId( customerId ).getDirectoryRoles().byId( roleId ).getUserMembers().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success( "Success!" );
this.getContext().getConsoleHelper().writeObject( userMembers, "User Members who are having the selected directory role" );
}
}

Просмотреть файл

@ -0,0 +1,49 @@
//-----------------------------------------------------------------------
//<copyright file="GetCustomerDirectoryRoles.java" company="Microsoft">
//Copyright (c) Microsoft Corporation. All rights reserved.
//</copyright>
//-----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerdirectoryroles;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.roles.DirectoryRole;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets a single customer details.
*/
public class GetCustomerDirectoryRoles
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetCustomerDirectoryRoles} class.
*
* @param context The scenario context.
*/
public GetCustomerDirectoryRoles( IScenarioContext context )
{
super( "Get Customer Directory Roles", context );
}
/**
* Executes the get customer details scenario.
*/
@Override
protected void runScenario()
{
String customerId = this.obtainCustomerId( "Enter the ID of the customer to retrieve" );
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
// Read all directory roles to get the first one's id.
this.getContext().getConsoleHelper().startProgress( "Getting Directory Role" );
ResourceCollection<DirectoryRole> directoryRoles = partnerOperations.getCustomers().byId( customerId ).getDirectoryRoles().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success( "Success!" );
this.getContext().getConsoleHelper().writeObject( directoryRoles, "Directory roles" );
}
}

Просмотреть файл

@ -0,0 +1,84 @@
//-----------------------------------------------------------------------
//<copyright file="RemoveCustomerUserMemberFromDirectoryRole.java" company="Microsoft">
//Copyright (c) Microsoft Corporation. All rights reserved.
//</copyright>
//-----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerdirectoryroles;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.roles.DirectoryRole;
import com.microsoft.store.partnercenter.models.roles.UserMember;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets a single customer details.
*/
public class RemoveCustomerUserMemberFromDirectoryRole
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetCustomerDetails} class.
*
* @param context The scenario context.
*/
public RemoveCustomerUserMemberFromDirectoryRole( IScenarioContext context )
{
super( "Remove Customer User Member From Directory Role", context );
}
/**
* Executes the get customer details scenario.
*/
@Override
protected void runScenario()
{
String customerId = this.obtainCustomerId( "Enter the ID of the customer to retrieve" );
String userId = this.obtainCustomerUserId( "Enter the ID of the customer-user to retrieve" );
String roleId = this.obtainDirectoryRoleId( "Enter the ID of the directory role to use" );
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
Customer selectedCustomer = partnerOperations.getCustomers().byId( customerId ).get();
CustomerUser customerUser = partnerOperations.getCustomers().byId( selectedCustomer.getId() ).getUsers().byId( userId ).get();
// Read all directory roles to find the one we need to use.
DirectoryRole selectedRole = null;
Iterable<DirectoryRole> directoryRoles = partnerOperations.getCustomers().byId( customerId ).getDirectoryRoles().get().getItems();
for (DirectoryRole role : directoryRoles )
{
if( role.getId().equalsIgnoreCase(roleId) )
{
selectedRole = role;
break;
}
}
UserMember userToUpdate = new UserMember();
userToUpdate.setUserPrincipalName ( customerUser.getUserPrincipalName() );
userToUpdate.setDisplayName ( customerUser.getDisplayName() );
userToUpdate.setId ( customerUser.getId() );
// Add this customer user to the selected directory role.
//UserMember userMemberAdded = partnerOperations.getCustomers().byId( customerId ).getDirectoryRoles().byId( selectedRole.getId() ).getUserMembers().create( userToUpdate );
try
{
// Remove customer user from selected directory role.
partnerOperations.getCustomers().byId( customerId ).getDirectoryRoles().byId( selectedRole.getId() ).getUserMembers().byId( userToUpdate.getId() ).delete();
System.out.println( "The user with user principal name: " + userToUpdate.getUserPrincipalName() + " was removed from directory role: " + selectedRole.getName() );
}
catch(Exception ex)
{
System.out.println( "Excepion removing user: " + ex );
}
// Cleaning up, delete user.
// partnerOperations.getCustomers().byId( selectedCustomer.getId() ).getUsers().byId( customerUser.getId() ).delete();
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerAvailabilities.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.products.Availability;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves the availabilities of a product's sku for a customer.
*/
public class GetCustomerAvailabilities extends BasePartnerScenario
{
public GetCustomerAvailabilities (IScenarioContext context)
{
super("Get availabilities for customer", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String productId = this.obtainProductId("Enter the ID of the corresponding product");
String skuId = this.obtainSkuId("Enter the ID of the corresponding sku");
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting availabilities for product {0} and sku {1} for customer {2}", productId, skuId, customerId));
ResourceCollection<Availability> skuAvailabilities = partnerOperations.getCustomers().byId(customerId).getProducts().byId(productId).getSkus().byId(skuId).getAvailabilities().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(skuAvailabilities, "Availabilities for customer");
}
}

Просмотреть файл

@ -0,0 +1,50 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerAvailabilitiesByTargetSegment.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.products.Availability;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves the availabilities of a product's sku for a customer that target a specific segment.
*/
public class GetCustomerAvailabilitiesByTargetSegment extends BasePartnerScenario
{
public GetCustomerAvailabilitiesByTargetSegment (IScenarioContext context)
{
super("Get availabilities for customer by segment", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String productId = this.obtainProductId("Enter the ID of the corresponding product");
String skuId = this.obtainSkuId("Enter the ID of the corresponding sku");
String segment =
this.getContext().getConsoleHelper().readNonEmptyString(
"The segment to filter the availabilities on",
"The segment can't be empty" );
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting sku availabilities for product {0} and sku {1} by segment {2} for customer {3}", productId, skuId, segment, customerId));
ResourceCollection<Availability> skuAvailabilities = partnerOperations.getCustomers().byId(customerId).getProducts().byId(productId).getSkus().byId(skuId).getAvailabilities().byTargetSegment(segment).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(skuAvailabilities, "Availabilities for customer by segment");
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerAvailability.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.products.Availability;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves the availability of a product's sku for a customer.
*/
public class GetCustomerAvailability extends BasePartnerScenario
{
public GetCustomerAvailability (IScenarioContext context)
{
super("Get availability for a customer", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String productId = this.obtainProductId("Enter the ID of the corresponding product");
String skuId = this.obtainSkuId("Enter the ID of the corresponding sku");
String availabilityId = this.obtainAvailabilityId("Enter the ID of the availability");
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting availability {0} for product {1} and sku {2} for customer {3}", availabilityId, productId, skuId, customerId));
Availability skuAvailability = partnerOperations.getCustomers().byId(customerId).getProducts().byId(productId).getSkus().byId(skuId).getAvailabilities().byId(availabilityId).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(skuAvailability, "Availability for customer");
}
}

Просмотреть файл

@ -0,0 +1,44 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerProduct.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.products.Product;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves product details for a customer.
*/
public class GetCustomerProduct extends BasePartnerScenario
{
public GetCustomerProduct (IScenarioContext context)
{
super("Get product for customer", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String productId = this.obtainProductId("Enter the ID of the corresponding product");
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting product {0} details for customer {1}", productId, customerId));
Product product = partnerOperations.getCustomers().byId(customerId).getProducts().byId(productId).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(product, "Product details for customer");
}
}

Просмотреть файл

@ -0,0 +1,48 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerProducts.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.products.Product;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves all the products in a catalog view that apply to a costumer.
*/
public class GetCustomerProducts extends BasePartnerScenario
{
public GetCustomerProducts (IScenarioContext context)
{
super("Get products for a customer", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String targetView =
this.getContext().getConsoleHelper().readNonEmptyString(
"Enter the target view to get its supported products",
"The target view can't be empty" );
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting products in catalog view {0} for customer {1}", targetView, customerId));
ResourceCollection<Product> products = partnerOperations.getCustomers().byId(customerId).getProducts().byTargetView(targetView).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(products, "Products for a customer");
}
}

Просмотреть файл

@ -0,0 +1,50 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerProductsByTargetSegment.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.products.Product;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves all the products in a catalog view that apply to a customer and that target a specific segment.
*/
public class GetCustomerProductsByTargetSegment extends BasePartnerScenario
{
public GetCustomerProductsByTargetSegment (IScenarioContext context)
{
super("Get products for customer by segment", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String targetView = this.getContext().getConsoleHelper().readNonEmptyString(
"Enter the target view to get its supported products",
"The target view can't be empty");
String segment = this.getContext().getConsoleHelper().readNonEmptyString(
"The segment to filter the products on",
"The segment can't be empty");
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting products in catalog view {0} by segment {1} for customer {2}", targetView, segment, customerId));
ResourceCollection<Product> products = partnerOperations.getCustomers().byId(customerId).getProducts().byTargetView(targetView).byTargetSegment(segment).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(products, "Products for customer by segment");
}
}

Просмотреть файл

@ -0,0 +1,45 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerSku.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.products.Sku;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves details of a product's sku for a customer.
*/
public class GetCustomerSku extends BasePartnerScenario
{
public GetCustomerSku (IScenarioContext context)
{
super("Get sku for customer", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String productId = this.obtainProductId("Enter the ID of the corresponding product");
String skuId = this.obtainSkuId("Enter the ID of the sku");
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting sku details for sku {0} from product {1} for customer {2}", skuId, productId, customerId));
Sku sku = partnerOperations.getCustomers().byId(customerId).getProducts().byId(productId).getSkus().byId(skuId).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(sku, MessageFormat.format("Sku details for customer", skuId, productId));
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerSkuDownloadOptions.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.products.SkuDownloadOptions;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves the download options of a product's sku for a customer.
*/
public class GetCustomerSkuDownloadOptions extends BasePartnerScenario
{
public GetCustomerSkuDownloadOptions (IScenarioContext context)
{
super("Get sku download options for customer", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String productId = this.obtainProductId("Enter the ID of the corresponding product");
String skuId = this.obtainSkuId("Enter the ID of the corresponding sku");
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting the SKU download options for sku {0} from product {1} for customer {2}", skuId, productId, customerId));
ResourceCollection<SkuDownloadOptions> sku = partnerOperations.getCustomers().byId(customerId).getProducts().byId(productId).getSkus().byId(skuId).getDownloadOptions().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(sku, "Sku download options for customer");
}
}

Просмотреть файл

@ -0,0 +1,45 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerSkus.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.products.Sku;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves all the skus related to a product that apply to a customer.
*/
public class GetCustomerSkus extends BasePartnerScenario
{
public GetCustomerSkus (IScenarioContext context)
{
super("Get SKUs for a customer", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String productId = this.obtainProductId("Enter the ID of the corresponding product");
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting skus from product {0} for customer {1}", productId, customerId));
ResourceCollection<Sku> skus = partnerOperations.getCustomers().byId(customerId).getProducts().byId(productId).getSkus().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(skus, "Skus for customer");
}
}

Просмотреть файл

@ -0,0 +1,49 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerSkusByTargetSegment.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerproducts;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.products.Sku;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves all the skus related to a product that apply to a customer and that target a specific segment.
*/
public class GetCustomerSkusByTargetSegment extends BasePartnerScenario
{
public GetCustomerSkusByTargetSegment (IScenarioContext context)
{
super("Get skus for customer by segment", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer");
String productId = this.obtainProductId("Enter the ID of the corresponding product");
String segment =
this.getContext().getConsoleHelper().readNonEmptyString(
"The segment to filter the SKUs on",
"The segment can't be empty" );
this.getContext().getConsoleHelper().startProgress(
MessageFormat.format("Getting skus from product {0} by segment {1} for customer {2}", productId, segment, customerId));
ResourceCollection<Sku> skus = partnerOperations.getCustomers().byId(customerId).getProducts().byId(productId).getSkus().byTargetSegment(segment).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(skus, MessageFormat.format("Skus for customer {0} by segment {1}", productId, segment));
}
}

Просмотреть файл

@ -0,0 +1,49 @@
// -----------------------------------------------------------------------
// <copyright file="CheckDomainAvailability.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that checks if a domain is still available for a customer or not.
*/
public class CheckDomainAvailability extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #CheckDomainAvailability} class.
*
* @param context The scenario context.
*/
public CheckDomainAvailability(IScenarioContext context)
{
super("Check domain availability", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String domainPrefix = this.getContext().getConsoleHelper()
.readNonEmptyString("Enter a domain prefix to check its availability", "The entered domain is empty");
this.getContext().getConsoleHelper().startProgress("Checking");
boolean isDomainAvailable = partnerOperations.getDomains().byDomain(domainPrefix + ".onmicrosoft.com").exists();
this.getContext().getConsoleHelper().stopProgress();
if (!isDomainAvailable) {
this.getContext().getConsoleHelper().success("This domain prefix is available!");
} else {
this.getContext().getConsoleHelper().warning("This domain prefix is unavailable.");
}
}
}

Просмотреть файл

@ -0,0 +1,80 @@
// -----------------------------------------------------------------------
// <copyright file="CreateCustomer.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import java.util.Random;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.Address;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.customers.CustomerBillingProfile;
import com.microsoft.store.partnercenter.models.customers.CustomerCompanyProfile;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Creates a new customer for a partner.
*/
public class CreateCustomer
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #CreateCustomer} class.
*
* @param context The scenario context.
*/
public CreateCustomer( IScenarioContext context )
{
super( "Create a new customer", context );
}
/**
* executes the create customer scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
Address address = new Address();
address.setFirstName( "Gena" );
address.setLastName( "Soto" );
address.setAddressLine1( "One Microsoft Way" );
address.setCity( "Redmond" );
address.setState( "WA" );
address.setCountry( "US" );
address.setPostalCode( "98052" );
address.setPhoneNumber( "4255550101" );
CustomerBillingProfile billingProfile = new CustomerBillingProfile();
billingProfile.setCulture( "en-US" );
billingProfile.setEmail( "gena@wingtiptoys.com" );
billingProfile.setLanguage( "en" );
billingProfile.setCompanyName( "Wingtip Toys" + new Random().nextInt() );
billingProfile.setDefaultAddress( address );
CustomerCompanyProfile companyProfile = new CustomerCompanyProfile();
companyProfile.setDomain( "WingtipToys" + Math.abs( new Random().nextInt() ) + ".onmicrosoft.com" );
Customer customerToCreate = new Customer();
customerToCreate.setBillingProfile( billingProfile );
customerToCreate.setCompanyProfile( companyProfile );
this.getContext().getConsoleHelper().writeObject( customerToCreate, "New customer information" );
this.getContext().getConsoleHelper().startProgress( "Creating customer" );
Customer newCustomer = partnerOperations.getCustomers().create( customerToCreate );
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success( "Success!" );
this.getContext().getConsoleHelper().writeObject( newCustomer, "Created customer information" );
}
}

Просмотреть файл

@ -0,0 +1,64 @@
// -----------------------------------------------------------------------
// <copyright file="DeleteCustomerFromTipAccount.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
import com.microsoft.store.partnercenter.utils.StringHelper;
/**
* Deletes a customer from a testing in production account.
*/
public class DeleteCustomerFromTipAccount
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #DeleteCustomerFromTipAccount} class.
*
* @param context The scenario context.
*/
public DeleteCustomerFromTipAccount( IScenarioContext context )
{
super( "Delete customer from TIP account", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getAppPartnerOperations();
String customerIdToDelete = this.getContext().getConfiguration().getScenarioSettings().get("CustomerIdToDelete");
if ( StringHelper.isNullOrWhiteSpace( customerIdToDelete ) )
{
// prompt the user the enter the customer ID
customerIdToDelete =
this.getContext().getConsoleHelper().readNonEmptyString(
"Enter the ID of the customer to delete",
"The customer ID can't be empty");
}
else
{
System.out.println(
MessageFormat.format(
"Found customer ID: {0} in configuration.",
customerIdToDelete ) );
}
this.getContext().getConsoleHelper().startProgress("Deleting customer");
partnerOperations.getCustomers().byId(customerIdToDelete).delete();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success( "Customer successfully deleted" );
}
}

Просмотреть файл

@ -0,0 +1,61 @@
// -----------------------------------------------------------------------
// <copyright file="FilterCustomers.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.customers.CustomerSearchField;
import com.microsoft.store.partnercenter.models.query.QueryFactory;
import com.microsoft.store.partnercenter.models.query.filters.FieldFilterOperation;
import com.microsoft.store.partnercenter.models.query.filters.SimpleFieldFilter;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Returns customers according to a provided filter.
*/
public class FilterCustomers
extends BasePartnerScenario
{
/**
* The search field.
*/
private final CustomerSearchField customerSearchField;
/**
* Initializes a new instance of the {@link #FilterCustomers} class.
*
* @param title The scenario title.
* @param customerSearchField The search filed.
* @param context The scenario context.
*/
public FilterCustomers( String title, CustomerSearchField customerSearchField, IScenarioContext context )
{
super( title, context );
this.customerSearchField = customerSearchField;
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String searchPrefix = this.getContext().getConsoleHelper().readNonEmptyString( "Enter the prefix to search for",
"The entered prefix is empty" );
this.getContext().getConsoleHelper().startProgress( "Filtering" );
ResourceCollection<Customer> customers =
partnerOperations.getCustomers().query( QueryFactory.getInstance().buildSimpleQuery( new SimpleFieldFilter( this.customerSearchField.toString(),
searchPrefix,
FieldFilterOperation.STARTS_WITH ) ) );
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( customers, "Customer matches" );
}
}

Просмотреть файл

@ -0,0 +1,44 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerDetails.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets a single customer details.
*/
public class GetCustomerDetails
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetCustomerDetails} class.
*
* @param context The scenario context.
*/
public GetCustomerDetails( IScenarioContext context )
{
super( "Get a customer details", context );
}
/**
* Executes the get customer details scenario.
*/
@Override
protected void runScenario()
{
String customerIdToRetrieve = this.obtainCustomerId( "Enter the ID of the customer to retrieve" );
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Retrieving customer" );
Customer customerDetails = partnerOperations.getCustomers().byId( customerIdToRetrieve ).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( customerDetails, "Customer details" );
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerManagedServices.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.managedservices.ManagedService;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets a customer list of managed services.
*/
public class GetCustomerManagedServices
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetCustomerManagedServices} class.
*
* @param context The scenario context.
*/
public GetCustomerManagedServices( IScenarioContext context )
{
super( "Get customer managed services", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the customer's managed services" );
ResourceCollection<ManagedService> managedServices =
partnerOperations.getCustomers().byId( customerId ).getManagedServices().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( managedServices, "Customer managed services" );
}
}

Просмотреть файл

@ -0,0 +1,44 @@
//-----------------------------------------------------------------------
//<copyright file="GetCustomerQualification.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
//</copyright>
//-----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.customers.CustomerQualification;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that gets customer qualification
*/
public class GetCustomerQualification
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #CreateOrder} class.
*
* @param context The scenario context.
*/
public GetCustomerQualification( IScenarioContext context )
{
super( "Get Customer Qualification", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
String customerIdToRetrieve = this.obtainCustomerId( "Enter the ID of the customer to retrieve" );
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Retrieving customer" );
CustomerQualification customerQualification = partnerOperations.getCustomers().byId( customerIdToRetrieve ).getQualification().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( customerQualification, "Customer Qualification" );
}
}

Просмотреть файл

@ -0,0 +1,45 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerRelationshipRequest.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.relationshiprequests.CustomerRelationshipRequest;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets the request which establishes a relationship between the partner and their customers.
*/
public class GetCustomerRelationshipRequest
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetCustomerRelationshipRequest} class.
*
* @param context The scenario context.
*/
public GetCustomerRelationshipRequest( IScenarioContext context )
{
super( "Get customer relationship request", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Retrieving customer relationship request" );
CustomerRelationshipRequest customerRelationshipRequest =
partnerOperations.getCustomers().getRelationshipRequests().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( customerRelationshipRequest,
"Customer relationship request" );
}
}

Просмотреть файл

@ -0,0 +1,87 @@
// -----------------------------------------------------------------------
// <copyright file="GetPagedCustomers.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.enumerators.IResourceCollectionEnumerator;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.query.QueryFactory;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
import com.microsoft.store.partnercenter.samples.helpers.ConsoleHelper;
/**
* Gets a partner customers in pages.
*/
public class GetPagedCustomers
extends BasePartnerScenario
{
/**
* The customer page size.
*/
private final int customerPageSize;
/**
* Initializes a new instance of the {@link #GetPagedCustomers} class.
*
* @param context The scenario context.
* @param customerPageSize The number of customers to return per page.
*/
public GetPagedCustomers( IScenarioContext context )
{
this( context, 0 );
}
public GetPagedCustomers( IScenarioContext context, int customerPageSize )
{
super( "Get Paged customers", context );
this.customerPageSize = customerPageSize;
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Querying customers" );
// query the customers, get the first page if a page size was set, otherwise get all customers
SeekBasedResourceCollection<Customer> customersPage = ( this.customerPageSize <= 0 )
? partnerOperations.getCustomers().get()
: partnerOperations.getCustomers().query( QueryFactory.getInstance().buildIndexedQuery( this.customerPageSize ) );
this.getContext().getConsoleHelper().stopProgress();
// create a customer enumerator which will aid us in traversing the customer pages
IResourceCollectionEnumerator<SeekBasedResourceCollection<Customer>> customersEnumerator =
partnerOperations.getEnumerators().getCustomers().create( customersPage );
int pageNumber = 1;
while ( customersEnumerator.hasValue() )
{
// print the current customer results page
this.getContext().getConsoleHelper().writeObject(
customersEnumerator.getCurrent(),
MessageFormat.format( "Customer Page: {0}",pageNumber++ ) );
System.out.println();
System.out.println( "Press Enter to retrieve the next customers page" );
ConsoleHelper.getInstance().getScanner().nextLine();
this.getContext().getConsoleHelper().startProgress( "Getting next customers page" );
// get the next page of customers
customersEnumerator.next();
this.getContext().getConsoleHelper().stopProgress();
}
}
}

Просмотреть файл

@ -0,0 +1,55 @@
// -----------------------------------------------------------------------
// <copyright file="UpdateCustomerBillingProfile.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.customers.CustomerBillingProfile;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that updates a customer's billing profile.
*/
public class UpdateCustomerBillingProfile
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #UpdateCustomerBillingProfile} class.
*
* @param context The scenario context.
*/
public UpdateCustomerBillingProfile( IScenarioContext context )
{
super( "Update customer billing profile", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting customer billing profile" );
CustomerBillingProfile billingProfile =
partnerOperations.getCustomers().byId( customerId ).getProfiles().getBilling().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( billingProfile, "Customer billing profile" );
this.getContext().getConsoleHelper().startProgress( "Updating the customer billing profile" );
// append some A's to some of the customer's billing profile properties
billingProfile.setFirstName( billingProfile.getFirstName() + "A" );
billingProfile.setLastName( billingProfile.getLastName() + "A" );
billingProfile.setCompanyName( billingProfile.getCompanyName() + "A" );
// update the billing profile
CustomerBillingProfile updatedBillingProfile =
partnerOperations.getCustomers().byId( customerId ).getProfiles().getBilling().update( billingProfile );
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( updatedBillingProfile, "Updated customer billing profile" );
}
}

Просмотреть файл

@ -0,0 +1,46 @@
//-----------------------------------------------------------------------
//<copyright file="UpdateCustomerQualification.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
//</copyright>
//-----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.customers.CustomerQualification;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Updates a single customer qualification.
*/
public class UpdateCustomerQualification
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #CreateOrder} class.
*
* @param context The scenario context.
*/
public UpdateCustomerQualification( IScenarioContext context )
{
super( "Update Customer Qualification", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
String customerIdToRetrieve = this.obtainCustomerId( "Enter the ID of the customer to update qualification to: " + CustomerQualification.EDUCATION );
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Retrieving customer" );
CustomerQualification customerQualification =
partnerOperations.getCustomers().byId( customerIdToRetrieve ).
getQualification().update( CustomerQualification.EDUCATION );
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( customerQualification, "Customer Qualification" );
}
}

Просмотреть файл

@ -0,0 +1,49 @@
//-----------------------------------------------------------------------
//<copyright file="ValidateCustomerAddress.java" company="Microsoft">
//Copyright (c) Microsoft Corporation. All rights reserved.
//</copyright>
//-----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.countryvalidationrules.CountryValidationRules;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that showcases country validation rules.
*/
public class ValidateCustomerAddress
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #ValidateCustomerAddress} class.
*
* @param context The scenario context.
*/
public ValidateCustomerAddress( IScenarioContext context )
{
super( "Validate customer address", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String countryCode = this.getContext().getConsoleHelper().readNonEmptyString(
"Enter the 2 digit country code to get its validation rules",
"The country code can't be empty");
this.getContext().getConsoleHelper().startProgress( "Retrieving country validation rules" );
CountryValidationRules countryValidationRules =
partnerOperations.getCountryValidationRules().byCountry( countryCode ).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( countryValidationRules, "Country validation rules" );
}
}

Просмотреть файл

@ -0,0 +1,42 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerServiceCostsLineItems.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerservicecosts;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.servicecosts.ServiceCostLineItem;
import com.microsoft.store.partnercenter.models.servicecosts.ServiceCostsBillingPeriod;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets Customer Service Costs Line Items.
*/
public class GetCustomerServiceCostsLineItems extends BasePartnerScenario
{
public GetCustomerServiceCostsLineItems (IScenarioContext context)
{
super("Get customer service costs line items", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer to get service costs line items");
this.getContext().getConsoleHelper().startProgress("Getting customer service costs line items");
ResourceCollection<ServiceCostLineItem> customerServiceCostsLineItems = partnerOperations.getCustomers().byId(customerId).getServiceCosts().byBillingPeriod(ServiceCostsBillingPeriod.MOST_RECENT).getLineItems().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(customerServiceCostsLineItems, "Customer Service Costs Line Items");
}
}

Просмотреть файл

@ -0,0 +1,41 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerServiceCostsSummary.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerservicecosts;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.servicecosts.ServiceCostsSummary;
import com.microsoft.store.partnercenter.models.servicecosts.ServiceCostsBillingPeriod;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets Customer Service Costs Summary.
*/
public class GetCustomerServiceCostsSummary extends BasePartnerScenario
{
public GetCustomerServiceCostsSummary (IScenarioContext context)
{
super("Get customer service costs summary", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer to get service costs summary");
this.getContext().getConsoleHelper().startProgress("Getting customer service costs summary");
ServiceCostsSummary customerServiceCostsSummary = partnerOperations.getCustomers().byId(customerId).getServiceCosts().byBillingPeriod(ServiceCostsBillingPeriod.MOST_RECENT).getSummary().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(customerServiceCostsSummary, "Customer Service Costs Summary");
}
}

Просмотреть файл

@ -0,0 +1,46 @@
//-----------------------------------------------------------------------
//<copyright file="CustomerSubscribedSkus.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
//</copyright>
//-----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customersubscribedskus;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.licenses.SubscribedSku;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves a single customer usage summary for usage based services.
*/
public class CustomerSubscribedSkus
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetCustomerUsageSummary} class.
*
* @param context The scenario context.
*/
public CustomerSubscribedSkus( IScenarioContext context )
{
super( "Get Customer Subscribed Skus", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerIdForUsage( "Enter the ID of the customer to retrieve usage summary" );
this.getContext().getConsoleHelper().startProgress( "Retrieving customer usage summary" );
ResourceCollection<SubscribedSku> customerSubscribedSkus =
partnerOperations.getCustomers().byId( customerId ).getSubscribedSkus().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( customerSubscribedSkus, "Customer Subscribed Skus" );
}
}

Просмотреть файл

@ -0,0 +1,57 @@
// -----------------------------------------------------------------------
// <copyright file="CreateCustomerUser.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.util.UUID;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.models.users.PasswordProfile;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
public class CreateCustomerUser extends BasePartnerScenario {
public CreateCustomerUser(IScenarioContext context) {
super("Creates a Customer User", context);
}
/**
* executes the create customer user scenario.
*/
@Override
protected void runScenario() {
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the customer to create new user for" );
Customer selectedCustomer = partnerOperations.getCustomers().byId( customerId ).get();
// read the selected customer id from the application state.
String selectedCustomerId = selectedCustomer.getId();
PasswordProfile passwordProfile = new PasswordProfile();
passwordProfile.setForceChangePassword(true);
passwordProfile.setPassword("Password!1");
CustomerUser userToCreate = new CustomerUser();
userToCreate.setPasswordProfile(passwordProfile);
userToCreate.setDisplayName( "TestDisplayName" );
userToCreate.setFirstName( "TestFirstName" );
userToCreate.setLastName( "TestLastName" );
userToCreate.setUsageLocation( "US" );
userToCreate.setUserPrincipalName(UUID.randomUUID().toString().toUpperCase() + "@" + selectedCustomer.getCompanyProfile().getDomain());
this.getContext().getConsoleHelper().writeObject( userToCreate, "New user Information" );
this.getContext().getConsoleHelper().startProgress( "Creating user" );
CustomerUser newCustomerUser = partnerOperations.getCustomers().byId(selectedCustomerId).getUsers().create( userToCreate );
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success( "Success!" );
this.getContext().getConsoleHelper().writeObject( newCustomerUser, "Created user Information" );
}
}

Просмотреть файл

@ -0,0 +1,95 @@
// -----------------------------------------------------------------------
// <copyright file="CustomerUserAssignGroup1Licenses.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.licenses.License;
import com.microsoft.store.partnercenter.models.licenses.LicenseAssignment;
import com.microsoft.store.partnercenter.models.licenses.LicenseGroupId;
import com.microsoft.store.partnercenter.models.licenses.LicenseUpdate;
import com.microsoft.store.partnercenter.models.licenses.SubscribedSku;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Assign customer user a group1 license.
*/
public class CustomerUserAssignGroup1Licenses extends BasePartnerScenario
{
public CustomerUserAssignGroup1Licenses (IScenarioContext context)
{
super("Assign customer user a group1 license", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer");
String userId = this.obtainCustomerUserId("Enter the ID of the customer user to assign license");
this.getContext().getConsoleHelper().startProgress("Getting Subscribed SKUs");
List<LicenseGroupId> groupIds = new ArrayList<LicenseGroupId>();
// A list of the groupids
// Group1 This group has all products whose license can be managed in the Azure Active Directory (AAD).
groupIds.add(LicenseGroupId.GROUP1);
// Get the customer's group1 subscribed SKUs information.
ResourceCollection<SubscribedSku> customerGroup1SubscribedSkus = partnerOperations.getCustomers().byId(customerId).getSubscribedSkus().get(groupIds);
this.getContext().getConsoleHelper().stopProgress();
// Prepare the license request.
LicenseUpdate updateLicense = new LicenseUpdate();
LicenseAssignment license = new LicenseAssignment();
// Select the first subscribed SKU.
SubscribedSku sku = customerGroup1SubscribedSkus.getItems().iterator().next();
// Assigning first subscribed sku as the license
license.setSkuId(sku.getProductSku().getId());
license.setExcludedPlans(null);
List<LicenseAssignment> licenseList = new ArrayList<LicenseAssignment>();
licenseList.add(license);
updateLicense.setLicensesToAssign(licenseList);
this.getContext().getConsoleHelper().startProgress("Assigning License");
partnerOperations.getCustomers().byId(customerId).getUsers().byId(userId).getLicenseUpdates().create(updateLicense);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().startProgress("Getting Assigned License");
// Get customer user assigned licenses information after assigning the license.
ResourceCollection<License> customerUserAssignedLicenses = partnerOperations.getCustomers().byId(customerId).getUsers().byId(userId).getLicenses().get(groupIds);
this.getContext().getConsoleHelper().stopProgress();
License userLicense = null;
for (License l : customerUserAssignedLicenses.getItems()) {
if(license.getSkuId().equals(l.getProductSku().getId()))
{
userLicense = l;
}
}
this.getContext().getConsoleHelper().writeObject(userLicense, "Assigned License");
}
}

Просмотреть файл

@ -0,0 +1,95 @@
// -----------------------------------------------------------------------
// <copyright file="CustomerUserAssignGroup2Licenses.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.licenses.License;
import com.microsoft.store.partnercenter.models.licenses.LicenseAssignment;
import com.microsoft.store.partnercenter.models.licenses.LicenseGroupId;
import com.microsoft.store.partnercenter.models.licenses.LicenseUpdate;
import com.microsoft.store.partnercenter.models.licenses.SubscribedSku;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Assign customer user a group2 license.
*/
public class CustomerUserAssignGroup2Licenses extends BasePartnerScenario
{
public CustomerUserAssignGroup2Licenses (IScenarioContext context)
{
super("Assign customer user a group2 license", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer");
String userId = this.obtainCustomerUserId("Enter the ID of the customer user to assign license");
this.getContext().getConsoleHelper().startProgress("Getting Subscribed SKUs");
List<LicenseGroupId> groupIds = new ArrayList<LicenseGroupId>();
// A list of the groupids
// Group2 This group contains products that cant be managed in Azure Active Directory
groupIds.add(LicenseGroupId.GROUP2);
// Get the customer's group1 subscribed SKUs information.
ResourceCollection<SubscribedSku> customerGroup2SubscribedSkus = partnerOperations.getCustomers().byId(customerId).getSubscribedSkus().get(groupIds);
this.getContext().getConsoleHelper().stopProgress();
// Prepare the license request.
LicenseUpdate updateLicense = new LicenseUpdate();
LicenseAssignment license = new LicenseAssignment();
// Select the first subscribed SKU.
SubscribedSku sku = customerGroup2SubscribedSkus.getItems().iterator().next();
// Assigning first subscribed sku as the license
license.setSkuId(sku.getProductSku().getId());
license.setExcludedPlans(null);
List<LicenseAssignment> licenseList = new ArrayList<LicenseAssignment>();
licenseList.add(license);
updateLicense.setLicensesToAssign(licenseList);
this.getContext().getConsoleHelper().startProgress("Assigning License");
partnerOperations.getCustomers().byId(customerId).getUsers().byId(userId).getLicenseUpdates().create(updateLicense);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().startProgress("Getting Assigned License");
// Get customer user assigned licenses information after assigning the license.
ResourceCollection<License> customerUserAssignedLicenses = partnerOperations.getCustomers().byId(customerId).getUsers().byId(userId).getLicenses().get(groupIds);
this.getContext().getConsoleHelper().stopProgress();
License userLicense = null;
for (License l : customerUserAssignedLicenses.getItems()) {
if(license.getSkuId().equals(l.getProductSku().getId()))
{
userLicense = l;
}
}
this.getContext().getConsoleHelper().writeObject(userLicense, "Assigned License");
}
}

Просмотреть файл

@ -0,0 +1,149 @@
// -----------------------------------------------------------------------
// <copyright file="CustomerUserAssignLicenses.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.licenses.License;
import com.microsoft.store.partnercenter.models.licenses.LicenseAssignment;
import com.microsoft.store.partnercenter.models.licenses.LicenseUpdate;
import com.microsoft.store.partnercenter.models.licenses.ServicePlan;
import com.microsoft.store.partnercenter.models.licenses.SubscribedSku;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.models.users.PasswordProfile;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
public class CustomerUserAssignLicenses extends BasePartnerScenario {
public CustomerUserAssignLicenses(IScenarioContext context) {
super("Assign licenses to a Customer User", context);
}
/***
* Executes the scenario
*/
@Override
protected void runScenario() {
Customer selectedCustomer = new Customer();
String custIdToUse = obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting customers" );
// get the customers
@SuppressWarnings("unused")
SeekBasedResourceCollection<Customer> customerList = partnerOperations.getCustomers().get();
boolean isCustomerWithSubscribedSkusExist = false;
ResourceCollection<SubscribedSku> customerSubscribedSkus = null;
//for ( Customer customer : customerList.getItems() )
{
//if ( customer.getId() != "6ffcc08f-4073-44c3-83f0-07c1d60f7274" )
// continue;
// get customer's subscribed skus information.
customerSubscribedSkus = partnerOperations.getCustomers().byId( custIdToUse ).getSubscribedSkus().get();
if (customerSubscribedSkus != null && customerSubscribedSkus.getTotalCount() > 0)
{
selectedCustomer = partnerOperations.getCustomers().byId( custIdToUse ).get();
isCustomerWithSubscribedSkusExist = true;
//break;
}
}
if (!isCustomerWithSubscribedSkusExist)
{
System.out.println("No customer with SubscribedSkus was found.");
}
else
{
// Create a user for this customer.
PasswordProfile passwordProfile = new PasswordProfile();
passwordProfile.setForceChangePassword(true);
passwordProfile.setPassword("Password!1");
CustomerUser userToCreate = new CustomerUser();
userToCreate.setPasswordProfile(passwordProfile);
userToCreate.setDisplayName( "TestDisplayName" );
userToCreate.setFirstName( "TestFirstName" );
userToCreate.setLastName( "TestLastName" );
userToCreate.setUsageLocation( "US" );
userToCreate.setUserPrincipalName(UUID.randomUUID().toString().toUpperCase() + "@" + selectedCustomer.getCompanyProfile().getDomain());
CustomerUser createdUser = partnerOperations.getCustomers().byId( selectedCustomer.getId() ).getUsers().create( userToCreate );
// Prepare license request.
LicenseUpdate updateLicense = new LicenseUpdate();
String userId = createdUser.getId();
// Select the first subscribed sku.
SubscribedSku sku = customerSubscribedSkus.getItems().iterator().next();
LicenseAssignment license = new LicenseAssignment();
license.setSkuId ( sku.getProductSku().getId() );
license.setExcludedPlans( null );
List<LicenseAssignment> licenseList = new ArrayList<LicenseAssignment>();
licenseList.add(license);
updateLicense.setLicensesToAssign ( licenseList );
// Assign licenses to the user.
LicenseUpdate assignLicense = partnerOperations.getCustomers().byId( selectedCustomer.getId() ).getUsers().byId( userId ).getLicenseUpdates().create( updateLicense );
if(assignLicense == null)
{
System.out.println("Null value was returned");
}
// get customer user assigned licenses information after assigning the license.
ResourceCollection<License> customerUserAssignedLicenses = partnerOperations.getCustomers().byId( selectedCustomer.getId() ).getUsers().byId( userId ).getLicenses().get();
if (customerUserAssignedLicenses != null && customerUserAssignedLicenses.getTotalCount() > 0)
{
System.out.println("License was successfully assigned to the user.");
License userLicense = customerUserAssignedLicenses.getItems().iterator().next();
Iterable<ServicePlan> servicePlans = userLicense.getServicePlans();
System.out.println("Customer User License ServicePlans ");
for (ServicePlan servicePlan : servicePlans)
{
System.out.println( "Customer User License service plan display name: " + servicePlan.getDisplayName() );
System.out.println( "Customer User License service plan service name: " + servicePlan.getServiceName() );
System.out.println( "Customer User License service plan service id: " + servicePlan.getId() );
System.out.println( "Customer User License service plan capability status: " + servicePlan.getCapabilityStatus() );
System.out.println();
}
}
// Remove the assigned license.
updateLicense.setLicensesToAssign ( null );
List<String> licensesToRemove = new ArrayList<String>();
licensesToRemove.add( sku.getProductSku().getId() );
updateLicense.setLicensesToRemove ( licensesToRemove );
assignLicense = partnerOperations.getCustomers().byId( selectedCustomer.getId() ).getUsers().byId( userId ).getLicenseUpdates().create( updateLicense );
// get customer user assigned licenses information after removing the license.
customerUserAssignedLicenses = partnerOperations.getCustomers().byId( selectedCustomer.getId() ).getUsers().byId( userId ).getLicenses().get();
if (customerUserAssignedLicenses != null && customerUserAssignedLicenses.getTotalCount() > 0)
{
System.out.println("Remove license operation failed.");
}
else
{
System.out.println("License was successfully removed.");
}
// Try to delete the created user.
partnerOperations.getCustomers().byId( selectedCustomer.getId() ).getUsers().byId( createdUser.getId() ).delete();
}
}
}

Просмотреть файл

@ -0,0 +1,54 @@
// -----------------------------------------------------------------------
// <copyright file="CustomerUserAssignedGroup1AndGroup2Licenses.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.licenses.License;
import com.microsoft.store.partnercenter.models.licenses.LicenseGroupId;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Get customer user assigned group1 and group2 licenses
*/
public class CustomerUserAssignedGroup1AndGroup2Licenses extends BasePartnerScenario
{
public CustomerUserAssignedGroup1AndGroup2Licenses (IScenarioContext context)
{
super("Get customer user assigned group1 and group2 licenses", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer");
String userId = this.obtainCustomerUserId("Enter the ID of the customer user to get assigned licenses");
this.getContext().getConsoleHelper().startProgress("Getting customer user assigned licenses");
List<LicenseGroupId> groupIds = new ArrayList<LicenseGroupId>();
// Get the customer user assigned group1 and group2 licenses information
// Group1 This group has all products whose license can be managed in the Azure Active Directory (AAD).
// Group2 This group contains products that cant be managed in Azure Active Directory
groupIds.add(LicenseGroupId.GROUP1);
groupIds.add(LicenseGroupId.GROUP2);
ResourceCollection<License> customerUserAssignedGroup1Group2Licenses = partnerOperations.getCustomers().byId(customerId).getUsers().byId(userId).getLicenses().get(groupIds);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(customerUserAssignedGroup1Group2Licenses, "Customer User Assigned Group1 and Group2 Licenses");
}
}

Просмотреть файл

@ -0,0 +1,52 @@
// -----------------------------------------------------------------------
// <copyright file="CustomerUserAssignedGroup1Licenses.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.licenses.License;
import com.microsoft.store.partnercenter.models.licenses.LicenseGroupId;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Get customer user assigned group1 licenses
*/
public class CustomerUserAssignedGroup1Licenses extends BasePartnerScenario
{
public CustomerUserAssignedGroup1Licenses (IScenarioContext context)
{
super("Get customer user assigned group1 licenses", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer");
String userId = this.obtainCustomerUserId("Enter the ID of the customer user to get assigned licenses");
this.getContext().getConsoleHelper().startProgress("Getting customer user assigned licenses");
List<LicenseGroupId> groupIds = new ArrayList<LicenseGroupId>();
// Get the customer user assigned group1 and group2 licenses information
// Group1 This group has all products whose license can be managed in the Azure Active Directory (AAD).
groupIds.add(LicenseGroupId.GROUP1);
ResourceCollection<License> customerUserAssignedGroup1Licenses = partnerOperations.getCustomers().byId(customerId).getUsers().byId(userId).getLicenses().get(groupIds);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(customerUserAssignedGroup1Licenses, "Customer User Assigned Group1 Licenses");
}
}

Просмотреть файл

@ -0,0 +1,52 @@
// -----------------------------------------------------------------------
// <copyright file="CustomerUserAssignedGroup2Licenses.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.licenses.License;
import com.microsoft.store.partnercenter.models.licenses.LicenseGroupId;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Get customer user assigned group2 licenses
*/
public class CustomerUserAssignedGroup2Licenses extends BasePartnerScenario
{
public CustomerUserAssignedGroup2Licenses (IScenarioContext context)
{
super("Get customer user assigned group2 licenses", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer");
String userId = this.obtainCustomerUserId("Enter the ID of the customer user to get assigned licenses");
this.getContext().getConsoleHelper().startProgress("Getting customer user assigned licenses");
List<LicenseGroupId> groupIds = new ArrayList<LicenseGroupId>();
// Get the customer user assigned group1 and group2 licenses information
// Group2 This group contains products that cant be managed in Azure Active Directory
groupIds.add(LicenseGroupId.GROUP2);
ResourceCollection<License> customerUserAssignedGroup2Licenses = partnerOperations.getCustomers().byId(customerId).getUsers().byId(userId).getLicenses().get(groupIds);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(customerUserAssignedGroup2Licenses, "Customer User Assigned Group2 Licenses");
}
}

Просмотреть файл

@ -0,0 +1,63 @@
// -----------------------------------------------------------------------
// <copyright file="CustomerUserAssignedLicenses.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.licenses.License;
import com.microsoft.store.partnercenter.models.licenses.ServicePlan;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets customer user assigned licenses.
*/
public class CustomerUserAssignedLicenses extends BasePartnerScenario
{
public CustomerUserAssignedLicenses(IScenarioContext context)
{
super("Get customer user assigned licenses", context);
}
/***
* Executes the scenario.
*/
@Override
protected void runScenario()
{
// Get the customer id of customer to run this scenario
String selectedCustomerId = this.obtainCustomerId();
ResourceCollection<License> customerUserAssignedLicenses = null;
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String selectedCustomerUserId = this.obtainCustomerUserId();
// get customer user assigned licenses information.
customerUserAssignedLicenses = partnerOperations.getCustomers().byId(selectedCustomerId).getUsers().byId(selectedCustomerUserId).getLicenses().get();
if (customerUserAssignedLicenses != null && customerUserAssignedLicenses.getTotalCount() > 0)
{
System.out.println( "Customer User Assigned Licenses Count: " + customerUserAssignedLicenses.getTotalCount() );
for ( License userLicense : customerUserAssignedLicenses.getItems() )
{
Iterable<ServicePlan> servicePlans = userLicense.getServicePlans();
System.out.println("Customer User License ServicePlans" );
for (ServicePlan servicePlan : servicePlans)
{
System.out.println( "Customer User License service plan display name: " + servicePlan.getDisplayName() );
System.out.println( "Customer User License service plan service name: " + servicePlan.getServiceName() );
System.out.println( "Customer User License service plan service id: " + servicePlan.getId() );
System.out.println( "Customer User License service plan capability status: " + servicePlan.getCapabilityStatus() );
System.out.println( "Customer User License service plan target type: " + servicePlan.getTargetType() );
System.out.println();
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// -----------------------------------------------------------------------
// <copyright file="CustomerUserRestore.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.models.users.UserState;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Restore a deleted customer user.
*/
public class CustomerUserRestore extends BasePartnerScenario
{
public CustomerUserRestore (IScenarioContext context)
{
super("Restore a deleted customer user", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the corresponding customer to restore customer user details");
String userId = this.obtainCustomerUserId("Enter the ID of the customer user to restore");
CustomerUser updatedCustomerUser = new CustomerUser();
updatedCustomerUser.setState(UserState.ACTIVE);
this.getContext().getConsoleHelper().startProgress("Restoring the customer user");
// restore customer user information using older upn.
CustomerUser restoredCustomerUserInfo = partnerOperations.getCustomers().byId(customerId).getUsers().byId(userId).patch(updatedCustomerUser);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(restoredCustomerUserInfo, "Restored customer user.");
}
}

Просмотреть файл

@ -0,0 +1,60 @@
// -----------------------------------------------------------------------
// <copyright file="DeleteCustomerUser.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.util.UUID;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.models.users.PasswordProfile;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
public class DeleteCustomerUser extends BasePartnerScenario {
public DeleteCustomerUser(IScenarioContext context) {
super("Deletes a Customer User", context);
}
/**
* executes the delete customer user scenario by creating a customer and then deleting it.
*/
@Override
protected void runScenario() {
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the customer to run the delete user scenario for" );
Customer selectedCustomer = partnerOperations.getCustomers().byId( customerId ).get();
// read the selected customer id from the application state.
String selectedCustomerId = selectedCustomer.getId();
PasswordProfile passwordProfile = new PasswordProfile();
passwordProfile.setForceChangePassword(true);
passwordProfile.setPassword("Password!1");
CustomerUser userToCreate = new CustomerUser();
userToCreate.setPasswordProfile(passwordProfile);
userToCreate.setDisplayName( "TestDisplayName" );
userToCreate.setFirstName( "TestFirstName" );
userToCreate.setLastName( "TestLastName" );
userToCreate.setUsageLocation( "US" );
userToCreate.setUserPrincipalName(UUID.randomUUID().toString().toUpperCase() + "@" + selectedCustomer.getCompanyProfile().getDomain());
this.getContext().getConsoleHelper().writeObject( userToCreate, "New user Information" );
this.getContext().getConsoleHelper().startProgress( "Creating user" );
CustomerUser customerUserToDelete = partnerOperations.getCustomers().byId(selectedCustomerId).getUsers().create( userToCreate );
this.getContext().getConsoleHelper().writeObject( customerUserToDelete, "Created user Information" );
// Now delete the newly created customer user
this.getContext().getConsoleHelper().startProgress( "Created user. Deleting the user" );
partnerOperations.getCustomers().byId(selectedCustomerId).getUsers().byId( customerUserToDelete.getId() ).delete();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success( "Success!" );
this.getContext().getConsoleHelper().writeObject( customerUserToDelete, "Deleted user Information" );
}
}

Просмотреть файл

@ -0,0 +1,68 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerInactiveUsers.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.enumerators.IResourceCollectionEnumerator;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.query.IQuery;
import com.microsoft.store.partnercenter.models.query.QueryFactory;
import com.microsoft.store.partnercenter.models.query.SeekOperation;
import com.microsoft.store.partnercenter.models.query.filters.FieldFilterOperation;
import com.microsoft.store.partnercenter.models.query.filters.SimpleFieldFilter;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
public class GetCustomerInactiveUsers extends BasePartnerScenario {
public GetCustomerInactiveUsers(IScenarioContext context) {
super("Get list of inactive Customer Users", context);
}
/***
* Executes the scenario
*/
@Override
protected void runScenario() {
// Get the customer id of customer to run this scenario
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the list of inactive users for customer id: " + customerId );
// Read the customer users for selectedCustomerId providing the filter option.
SimpleFieldFilter filter = new SimpleFieldFilter("UserStatus", "Inactive", FieldFilterOperation.EQUALS );
IQuery simpleQueryWithFilter = QueryFactory.getInstance().buildSimpleQuery(filter);
// Read inactive customer users in a batch
SeekBasedResourceCollection<CustomerUser> customerUsers = partnerOperations.getCustomers().byId(customerId).getUsers().query(simpleQueryWithFilter);
IResourceCollectionEnumerator<SeekBasedResourceCollection<CustomerUser>> customerUsersEnumerator = partnerOperations.getEnumerators().getCustomerUsers().create(customerUsers);
while ( customerUsersEnumerator.hasValue() )
{
System.out.println( "Customer user page count: " + customerUsersEnumerator.getCurrent().getTotalCount() );
for ( CustomerUser user : customerUsersEnumerator.getCurrent().getItems() )
{
System.out.println( "Customer User Id: " + user.getId() );
System.out.println( "Company User Name: " + user.getDisplayName() );
System.out.println( "Company User State: " + user.getState() );
System.out.println();
}
if ( customerUsers.getLinks().getNext() == null )
{
break;
}
IQuery seekQuery = QueryFactory.getInstance().buildSeekQuery( SeekOperation.NEXT, 0, 0, null, null, customerUsers.getContinuationToken() );
customerUsers = partnerOperations.getCustomers().byId(customerId).getUsers().query( seekQuery );
customerUsersEnumerator = partnerOperations.getEnumerators().getCustomerUsers().create( customerUsers );
}
}
}

Просмотреть файл

@ -0,0 +1,34 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerUserCollection.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
public class GetCustomerUserCollection extends BasePartnerScenario {
public GetCustomerUserCollection(IScenarioContext context) {
super("Get a customer users collection", context);
}
/**
* Executes the get customer users scenario.
*/
@Override
protected void runScenario() {
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting customer users collection" );
ResourceCollection<CustomerUser> users =
partnerOperations.getCustomers().byId( customerId ).getUsers().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( users, "Customer Users Collection" );
}
}

Просмотреть файл

@ -0,0 +1,38 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerUserDetails.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
public class GetCustomerUserDetails extends BasePartnerScenario
{
public GetCustomerUserDetails(IScenarioContext context)
{
super("Get information of a Customer User", context);
}
@Override
protected void runScenario()
{
String customerId = this.obtainCustomerId();
String customerUserId = this.obtainCustomerUserId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
// Get user details.
this.getContext().getConsoleHelper().startProgress(
"Retrieving user with id: " + customerUserId + "for customer: " + customerId);
CustomerUser customerUserInfo = partnerOperations.getCustomers().byId(customerId).getUsers()
.byId(customerUserId).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success("Success!");
this.getContext().getConsoleHelper().writeObject(customerUserInfo,
"Retrieved Customer user Information");
}
}

Просмотреть файл

@ -0,0 +1,67 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomerUserDirectoryRoles.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.roles.DirectoryRole;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
public class GetCustomerUserDirectoryRoles extends BasePartnerScenario {
/***
* Public constructor
*/
public GetCustomerUserDirectoryRoles(IScenarioContext context) {
super("Get directory roles assigned to a Customer User", context);
}
/***
* Executes the scenario.
*/
@Override
protected void runScenario() {
// Get the customer id of customer to run this scenario
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the customer to run the update user scenario for" );
Customer selectedCustomer = partnerOperations.getCustomers().byId( customerId ).get();
// read the selected customer id from the application state.
String selectedCustomerId = selectedCustomer.getId();
// get user directory roles.
SeekBasedResourceCollection<CustomerUser> allCustomerUsers = partnerOperations.getCustomers().byId(selectedCustomerId).getUsers().get();
CustomerUser selectedCustomerUser = null;
if( allCustomerUsers.getTotalCount() >= 1 )
{
selectedCustomerUser = allCustomerUsers.getItems().iterator().next();//..get .getbyId(selectedCustomerUser.Id).DirectoryRoles.Get();
}
ResourceCollection<DirectoryRole> userMemberships = partnerOperations.getCustomers().byId(selectedCustomerId).getUsers().byId(selectedCustomerUser.getId()).getDirectoryRoles().get();
if (userMemberships != null && userMemberships.getTotalCount() > 0)
{
System.out.println( "Customer user directory role count: " + userMemberships.getTotalCount() );
System.out.println( "User Principal Name: " + selectedCustomerUser.getUserPrincipalName() );
System.out.println( "Display Name: " + selectedCustomerUser.getDisplayName() );
System.out.println();
for ( DirectoryRole membership : userMemberships.getItems() )
{
System.out.println( "Role Id: " + membership.getId() );
System.out.println();
}
}
}
}

Просмотреть файл

@ -0,0 +1,76 @@
// -----------------------------------------------------------------------
// <copyright file="GetPagedCustomerUsers.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.enumerators.IResourceCollectionEnumerator;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.query.QueryFactory;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
import com.microsoft.store.partnercenter.samples.helpers.ConsoleHelper;
public class GetPagedCustomerUsers extends BasePartnerScenario {
/**
* The customer user page size.
*/
private final int customerUserPageSize;
public GetPagedCustomerUsers(IScenarioContext context) {
this( context, 0 );
}
public GetPagedCustomerUsers( IScenarioContext context, int customerUserPageSize )
{
super( "Get Paged customer users", context );
this.customerUserPageSize = customerUserPageSize;
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario() {
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the customer to run the get paged users scenario for" );
Customer selectedCustomer = partnerOperations.getCustomers().byId( customerId ).get();
// read the selected customer id from the application state.
String selectedCustomerId = selectedCustomer.getId();
// query the customers, get the first page if a page size was set, otherwise get all customers
SeekBasedResourceCollection<CustomerUser> customerUsersPage = ( this.customerUserPageSize <= 0 )
? partnerOperations.getCustomers().byId( selectedCustomerId ).getUsers().get()
: partnerOperations.getCustomers().byId( selectedCustomerId ).getUsers().query( QueryFactory.getInstance().buildIndexedQuery( this.customerUserPageSize ) );
this.getContext().getConsoleHelper().stopProgress();
// create a customer enumerator which will aid us in traversing the customer pages
IResourceCollectionEnumerator<SeekBasedResourceCollection<CustomerUser>> customerUsersEnumerator =
partnerOperations.getEnumerators().getCustomerUsers().create( customerUsersPage );
int pageNumber = 1;
while ( customerUsersEnumerator.hasValue() )
{
// print the current customer user results page
this.getContext().getConsoleHelper().writeObject( customerUsersEnumerator.getCurrent(),
MessageFormat.format( "Customer User Page: {0}",
pageNumber++ ) );
System.out.println();
System.out.println( "Press Enter to retrieve the next customer users page" );
ConsoleHelper.getInstance().getScanner().nextLine();
this.getContext().getConsoleHelper().startProgress( "Getting next customer users page" );
// get the next page of customers
customerUsersEnumerator.next();
this.getContext().getConsoleHelper().stopProgress();
}
}
}

Просмотреть файл

@ -0,0 +1,54 @@
// -----------------------------------------------------------------------
// <copyright file="SortedCustomerUsers.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.query.QueryFactory;
import com.microsoft.store.partnercenter.models.query.sort.Sort;
import com.microsoft.store.partnercenter.models.query.sort.SortDirection;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Sorts the customer users.
*/
public class SortedCustomerUsers extends BasePartnerScenario
{
public SortedCustomerUsers(IScenarioContext context) {
super("Get sorted list of Customer Users", context);
}
/***
* Execute the scenario
*/
@Override
protected void runScenario() {
// Get the customer id of customer to run this scenario
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the sorted list of customer users:" );
// Read the customer users for selectedCustomerId providing the sort option.
SeekBasedResourceCollection<CustomerUser> customerUsers = partnerOperations.getCustomers().byId( customerId ).getUsers().query(QueryFactory.getInstance().buildIndexedQuery(100, 0, null, new Sort("DisplayName", SortDirection.DESCENDING)));
if (customerUsers != null && customerUsers.getTotalCount() > 0)
{
System.out.println( "Customer user count: " + customerUsers.getTotalCount() );
System.out.println();
for ( CustomerUser user : customerUsers.getItems() )
{
System.out.println( "Name: " + user.getDisplayName() );
System.out.println( "Id: " + user.getId() );
System.out.println();
}
}
}
}

Просмотреть файл

@ -0,0 +1,79 @@
// -----------------------------------------------------------------------
// <copyright file="UpdateCustomerUser.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.customerusers;
import java.util.UUID;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.users.CustomerUser;
import com.microsoft.store.partnercenter.models.users.PasswordProfile;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that updates a customer user.
*/
public class UpdateCustomerUser extends BasePartnerScenario {
public UpdateCustomerUser(IScenarioContext context) {
super("Updates a Customer User", context);
}
/**
* executes the update customer user scenario by creating a customer and then
* updating it.
*/
@Override
protected void runScenario() {
String customerId = this.obtainCustomerId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper()
.startProgress("Getting the customer to run the update user scenario for");
Customer selectedCustomer = partnerOperations.getCustomers().byId(customerId).get();
// read the selected customer id from the application state.
String selectedCustomerId = selectedCustomer.getId();
PasswordProfile passwordProfile = new PasswordProfile();
passwordProfile.setForceChangePassword(true);
passwordProfile.setPassword("Password!1");
CustomerUser userToCreate = new CustomerUser();
userToCreate.setPasswordProfile(passwordProfile);
userToCreate.setDisplayName("TestDisplayName");
userToCreate.setFirstName("TestFirstName");
userToCreate.setLastName("TestLastName");
userToCreate.setUsageLocation("US");
userToCreate.setUserPrincipalName(UUID.randomUUID().toString().toUpperCase() + "@"
+ selectedCustomer.getCompanyProfile().getDomain());
this.getContext().getConsoleHelper().writeObject(userToCreate, "New user Information");
this.getContext().getConsoleHelper().startProgress("Creating user");
CustomerUser createdCustomerUser = partnerOperations.getCustomers().byId(selectedCustomerId).getUsers()
.create(userToCreate);
this.getContext().getConsoleHelper().writeObject(createdCustomerUser, "Created user Information");
// Specifying update attributes.
CustomerUser customerUserToUpdate = new CustomerUser();
passwordProfile.setPassword("testPw@!122B");
customerUserToUpdate.setPasswordProfile(passwordProfile);
customerUserToUpdate.setDisplayName("Michael Phelps");
customerUserToUpdate.setFirstName("Michael");
customerUserToUpdate.setLastName("Phelps");
customerUserToUpdate.setUsageLocation("US");
customerUserToUpdate.setUserPrincipalName(UUID.randomUUID().toString().toUpperCase() + "@"
+ selectedCustomer.getCompanyProfile().getDomain());
// Now update the newly created customer user
this.getContext().getConsoleHelper().startProgress("Created user. Updating the user");
CustomerUser updatedCustomerUser = partnerOperations.getCustomers().byId(selectedCustomerId).getUsers()
.byId(createdCustomerUser.getId()).patch(customerUserToUpdate);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success("Success!");
this.getContext().getConsoleHelper().writeObject(updatedCustomerUser, "Updated user Information");
}
}

Просмотреть файл

@ -0,0 +1,57 @@
// -----------------------------------------------------------------------
// <copyright file="CreateConfigurationPolicy.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.devicesdeployment.ConfigurationPolicy;
import com.microsoft.store.partnercenter.models.devicesdeployment.PolicySettingsType;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Creates a new configuration policy for devices.
*/
public class CreateConfigurationPolicy extends BasePartnerScenario
{
public CreateConfigurationPolicy (IScenarioContext context)
{
super("Create a new configuration policy", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer to create the configuration policy for");
List<PolicySettingsType> policySettings = new ArrayList<PolicySettingsType>();
policySettings.add(PolicySettingsType.OOBE_USER_NOT_LOCAL_ADMIN);
policySettings.add(PolicySettingsType.SKIP_EULA);
ConfigurationPolicy configurationPolicyToCreate = new ConfigurationPolicy();
configurationPolicyToCreate.setDescription("This configuration policy is created by the SDK samples");
configurationPolicyToCreate.setName("Test Config Policy");
configurationPolicyToCreate.setPolicySettings(policySettings);
this.getContext().getConsoleHelper().writeObject(configurationPolicyToCreate, "New configuration policy Information");
this.getContext().getConsoleHelper().startProgress("Creating Configuration Policy");
ConfigurationPolicy createdConfigurationPolicy = partnerOperations.getCustomers().byId(customerId).getConfigurationPolicies().create(configurationPolicyToCreate);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success("Success!");
this.getContext().getConsoleHelper().writeObject(createdConfigurationPolicy, "Created configuration policy Information");
}
}

Просмотреть файл

@ -0,0 +1,61 @@
// -----------------------------------------------------------------------
// <copyright file="CreateDeviceBatch.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.devicesdeployment.Device;
import com.microsoft.store.partnercenter.models.devicesdeployment.DeviceBatchCreationRequest;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Creates a new device batch with devices.
*/
public class CreateDeviceBatch extends BasePartnerScenario
{
public CreateDeviceBatch (IScenarioContext context)
{
super("Create a new device batch", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer to create the device batch for");
Device deviceToAdd = new Device();
deviceToAdd.setHardwareHash("DummyHash1234");
deviceToAdd.setProductKey("00329-00000-0003-AA606");
deviceToAdd.setSerialNumber("1R9-ZNP67");
List<Device> devicesToBeUploaded = new ArrayList<Device>();
devicesToBeUploaded.add(deviceToAdd);
DeviceBatchCreationRequest newDeviceBatch = new DeviceBatchCreationRequest();
newDeviceBatch.setBatchId("SDKTestDeviceBatch");
newDeviceBatch.setDevices(devicesToBeUploaded);
this.getContext().getConsoleHelper().writeObject(newDeviceBatch, "New device batch");
this.getContext().getConsoleHelper().startProgress("Creating device batch");
String trackingLocation = partnerOperations.getCustomers().byId(customerId).getDeviceBatches().create(newDeviceBatch);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(trackingLocation, "Tracking location to track the status");
this.getContext().getConsoleHelper().success("Create device batch request submitted successfully!");
}
}

Просмотреть файл

@ -0,0 +1,66 @@
// -----------------------------------------------------------------------
// <copyright file="CreateDevices.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.devicesdeployment.Device;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Creates new devices under an existing device batch.
*/
public class CreateDevices extends BasePartnerScenario
{
public CreateDevices (IScenarioContext context)
{
super("Create new devices", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer to create the devices for");
String deviceBatchId = this.obtainDeviceBatchId("Enter the ID of the Device batch to add the devices to");
List<Device> devicesToBeUploaded = new ArrayList<Device>();
Device device1ToAdd = new Device();
device1ToAdd.setHardwareHash("DummyHash1234");
device1ToAdd.setProductKey("00329-00000-0003-AA606");
device1ToAdd.setSerialNumber("1R9-ZNP67");
devicesToBeUploaded.add(device1ToAdd);
Device device2ToAdd = new Device();
device2ToAdd = new Device();
device2ToAdd.setHardwareHash("DummyHash12345");
device2ToAdd.setProductKey("00329-00000-0003-AA606");
device2ToAdd.setSerialNumber("1R9-ZNP67");
devicesToBeUploaded.add(device2ToAdd);
this.getContext().getConsoleHelper().writeObject(devicesToBeUploaded, "New devices");
this.getContext().getConsoleHelper().startProgress("Creating devices");
String trackingLocation = partnerOperations.getCustomers().byId(customerId).getDeviceBatches().byId(deviceBatchId).getDevices().create(devicesToBeUploaded);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(trackingLocation, "Tracking location to track the status");
this.getContext().getConsoleHelper().success("Create devices request submitted successfully!");
}
}

Просмотреть файл

@ -0,0 +1,41 @@
// -----------------------------------------------------------------------
// <copyright file="DeleteConfigurationPolicy.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Deletes a configuration policy.
*/
public class DeleteConfigurationPolicy extends BasePartnerScenario
{
public DeleteConfigurationPolicy (IScenarioContext context)
{
super("Delete a configuration policy", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer to delete a configuration policy");
String policyId = this.obtainConfigurationPolicyId("Enter the ID of the configuration policy to delete");
this.getContext().getConsoleHelper().writeObject(policyId, "Configuration policy to be deleted");
this.getContext().getConsoleHelper().startProgress("Deleting configuration policy");
partnerOperations.getCustomers().byId(customerId).getConfigurationPolicies().byId(policyId).delete();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success("Delete configuration policy request submitted successfully!");
}
}

Просмотреть файл

@ -0,0 +1,42 @@
// -----------------------------------------------------------------------
// <copyright file="DeleteDevice.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Deletes a device.
*/
public class DeleteDevice extends BasePartnerScenario
{
public DeleteDevice(IScenarioContext context)
{
super("Delete a device", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer to delete a device");
String deviceBatchId = this.obtainDeviceBatchId("Enter the ID of the Device batch to retrieve the devices of");
String deviceId = this.obtainDeviceId("Enter the ID of the device to delete");
this.getContext().getConsoleHelper().writeObject(deviceId, "Device to be deleted");
this.getContext().getConsoleHelper().startProgress("Deleting device");
partnerOperations.getCustomers().byId(customerId).getDeviceBatches().byId(deviceBatchId).getDevices().byId(deviceId).delete();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success("Deleted the device successfully!");
}
}

Просмотреть файл

@ -0,0 +1,41 @@
// -----------------------------------------------------------------------
// <copyright file="GetAllConfigurationPolicies.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.devicesdeployment.ConfigurationPolicy;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets all configuration policies of a customer.
*/
public class GetAllConfigurationPolicies extends BasePartnerScenario
{
public GetAllConfigurationPolicies (IScenarioContext context)
{
super("Get all configuration policies", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer to get the configuration policies");
this.getContext().getConsoleHelper().startProgress("Querying Configuration policies");
ResourceCollection<ConfigurationPolicy> configPolicies = partnerOperations.getCustomers().byId(customerId).getConfigurationPolicies().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(configPolicies, "Configuration policies");
}
}

Просмотреть файл

@ -0,0 +1,41 @@
// -----------------------------------------------------------------------
// <copyright file="GetBatchUploadStatus.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.devicesdeployment.BatchUploadDetails;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets batch upload status.
*/
public class GetBatchUploadStatus extends BasePartnerScenario
{
public GetBatchUploadStatus (IScenarioContext context)
{
super("Get Batch Upload Status", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the Customer Id to get the status for");
String trackingId = this.obtainBatchUploadStatusTrackingId("Enter the batch upload status tracking Id to get the status of");
this.getContext().getConsoleHelper().startProgress("Querying the status");
BatchUploadDetails status = partnerOperations.getCustomers().byId(customerId).getBatchUploadStatus().byId(trackingId).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(status, "Tracking status");
}
}

Просмотреть файл

@ -0,0 +1,42 @@
// -----------------------------------------------------------------------
// <copyright file="GetDevices.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.devicesdeployment.Device;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets devices of a device batch.
*/
public class GetDevices extends BasePartnerScenario
{
public GetDevices (IScenarioContext context)
{
super("Get devces", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the Customer Id to get the devices for");
String deviceBatchId = this.obtainDeviceBatchId("Enter the ID of the Device batch to retrieve the devices of");
this.getContext().getConsoleHelper().startProgress("Querying for the devices");
ResourceCollection<Device> devices = partnerOperations.getCustomers().byId(customerId).getDeviceBatches().byId(deviceBatchId).getDevices().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(devices, "Devices");
}
}

Просмотреть файл

@ -0,0 +1,41 @@
// -----------------------------------------------------------------------
// <copyright file="GetDevicesBatches.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.devicesdeployment.DeviceBatch;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets devices batches.
*/
public class GetDevicesBatches extends BasePartnerScenario
{
public GetDevicesBatches (IScenarioContext context)
{
super("Get devices batches", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the Customer Id to get the devices batches for");
this.getContext().getConsoleHelper().startProgress("Querying for the devices batches");
ResourceCollection<DeviceBatch> devicesBatches = partnerOperations.getCustomers().byId(customerId).getDeviceBatches().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(devicesBatches, "Device batches");
}
}

Просмотреть файл

@ -0,0 +1,56 @@
// -----------------------------------------------------------------------
// <copyright file="UpdateConfigurationPolicy.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.devicesdeployment.ConfigurationPolicy;
import com.microsoft.store.partnercenter.models.devicesdeployment.PolicySettingsType;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Updates configuration policy.
*/
public class UpdateConfigurationPolicy extends BasePartnerScenario
{
public UpdateConfigurationPolicy (IScenarioContext context)
{
super("Update configuration policy", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the Customer Id to update the configuration policy for");
String configurationPolicyId = this.obtainConfigurationPolicyId("Enter the ID of the Configuration Policy to update");
List<PolicySettingsType> policySettings = new ArrayList<PolicySettingsType>();
policySettings.add(PolicySettingsType.OOBE_USER_NOT_LOCAL_ADMIN);
policySettings.add(PolicySettingsType.REMOVE_OEM_PREINSTALLS);
ConfigurationPolicy configPolicyToBeUpdated = new ConfigurationPolicy();
configPolicyToBeUpdated.setId(configurationPolicyId);
configPolicyToBeUpdated.setName("Test Config Policy");
configPolicyToBeUpdated.setPolicySettings(policySettings);
this.getContext().getConsoleHelper().startProgress("Updating configuration policy");
ConfigurationPolicy updatedConfigurationPolicy = partnerOperations.getCustomers().byId(customerId).getConfigurationPolicies().byId(configurationPolicyId).patch(configPolicyToBeUpdated);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(updatedConfigurationPolicy, "Updated configuration policy");
}
}

Просмотреть файл

@ -0,0 +1,72 @@
// -----------------------------------------------------------------------
// <copyright file="UpdateDevicesPolicy.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.devicesdeployment;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.devicesdeployment.Device;
import com.microsoft.store.partnercenter.models.devicesdeployment.DevicePolicyUpdateRequest;
import com.microsoft.store.partnercenter.models.devicesdeployment.PolicyCategory;
import com.microsoft.store.partnercenter.models.utils.KeyValuePair;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Updates devices with configuration policy.
*/
public class UpdateDevicesPolicy extends BasePartnerScenario
{
public UpdateDevicesPolicy(IScenarioContext context)
{
super("Update configuration policy of devices", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the Customer Id to update the devices for");
String configurationPolicyId = this.obtainConfigurationPolicyId("Enter the ID of the Configuration Policy to update the device with");
String deviceId = this.obtainDeviceId("Enter the Device Id to update");
List<KeyValuePair<PolicyCategory, String>> policyToBeAded = new ArrayList<KeyValuePair<PolicyCategory, String>>();
policyToBeAded.add(
new KeyValuePair<PolicyCategory, String>
(
PolicyCategory.OOBE,
configurationPolicyId
)
);
Device deviceToUpdate = new Device();
deviceToUpdate.setId(deviceId);
deviceToUpdate.setPolicies(policyToBeAded);
List<Device> devices = new ArrayList<Device>();
devices.add(deviceToUpdate);
DevicePolicyUpdateRequest devicePolicyUpdateRequest = new DevicePolicyUpdateRequest();
devicePolicyUpdateRequest.setDevices(devices);
this.getContext().getConsoleHelper().startProgress("Updating Devices with Configuration Policy");
String trackingLocation = partnerOperations.getCustomers().byId(customerId).getDevicePolicy().update(devicePolicyUpdateRequest);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(trackingLocation, "Tracking Location to track the status");
this.getContext().getConsoleHelper().success("Update Devices Request submitted successfully!");
}
}

Просмотреть файл

@ -0,0 +1,41 @@
// -----------------------------------------------------------------------
// <copyright file="GetEntitlements.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.entitlements;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.entitlements.Entitlement;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Get customer entitlements.
*/
public class GetEntitlements extends BasePartnerScenario
{
public GetEntitlements (IScenarioContext context)
{
super("Get entitlements", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer to retrieve entitlements for");
this.getContext().getConsoleHelper().startProgress("Retrieving customer entitlements");
ResourceCollection<Entitlement> entitlements = partnerOperations.getCustomers().byId(customerId).getEntitlements().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(entitlements, "Artifact Details");
}
}

Просмотреть файл

@ -0,0 +1,189 @@
// -----------------------------------------------------------------------
// <copyright file="ConsoleHelper.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.helpers;
import java.util.Scanner;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.microsoft.store.partnercenter.utils.StringHelper;
/**
* Provides useful helpers that aid in writing to the console.
*/
public class ConsoleHelper
{
/**
* A lazy reference to the singleton console helper instance.
*/
private static ConsoleHelper instance = null;
private Scanner scanner = new Scanner( System.in );
/**
* Prevents a default instance of the {@link #ConsoleHelper} class from being created.
*/
private ConsoleHelper()
{
}
/**
* Gets the single instance of the {@link #ConsoleHelper} .
*/
public static ConsoleHelper getInstance()
{
if ( instance == null )
{
instance = new ConsoleHelper();
}
return instance;
}
/**
* Writes a success message to the console.
*
* @param message The message to write.
* @param newLine Whether or not to write a new line after the message.
*/
public void success( String message )
{
this.success( message, true );
}
public void success( String message, Boolean newLine )
{
System.out.print( "[success] " + message );
if ( newLine )
{
System.out.println();
}
}
/**
* Writes a warning message to the console.
*
* @param message The message to write.
* @param newLine Whether or not to write a new line after the message.
*/
public void warning( String message )
{
this.warning( message, true );
}
public void warning( String message, boolean newLine )
{
System.out.print( message );
if ( newLine )
{
System.out.println();
}
}
/**
* Writes an error message to the console.
*
* @param message The message to write.
* @param newLine Whether or not to write a new line after the message.
*/
public void error( String message )
{
this.error( message, true );
}
public void error( String message, boolean newLine )
{
System.out.print( "[Error] " + message );
if ( newLine )
{
System.out.println();
}
}
public void startProgress( String message )
{
System.out.println( message + "... " );
}
public void stopProgress()
{
System.out.println( "Done!" );
}
public Scanner getScanner()
{
return this.scanner;
}
/**
* Reads a non empty string from the console.
*
* @param promptMessage The prompt message to display.
* @param validationMessage The error message to show in case of user input error.
* @return The string input from the console.
*/
public String readNonEmptyString( String promptMessage, String validationMessage )
{
String input;
validationMessage = validationMessage != null ? validationMessage : "Enter a non-empty value";
while ( true )
{
System.out.println( promptMessage );
input = this.getScanner().nextLine();
if ( StringHelper.isNullOrWhiteSpace( input ) )
{
this.error( validationMessage );
}
else
{
break;
}
}
return input;
}
/**
* Reads a string from the console (it can be empty as it is intended to be used with optional values).
*
* @param promptMessage The prompt message to display.
* @return The string input from the console.
*/
public String readOptionalString(String promptMessage)
{
String input;
System.out.println( promptMessage );
input = this.getScanner().nextLine();
return input;
}
/**
* Writes an object and its properties recursively to the console. Properties are automatically indented.
*
* @param object The object to print to the console.
* @param title An optional title to display.
* @param indent The starting indentation.
*/
public void writeObject( Object object, String title )
{
ObjectMapper mapper =
new ObjectMapper().configure( SerializationFeature.INDENT_OUTPUT, true ).registerModule( new JodaModule() );
;
System.out.println();
System.out.println( title );
System.out.println( new String( new char[90] ).replace( '\0', '-' ) );
try
{
System.out.println( mapper.writeValueAsString( object ) );
}
catch ( JsonProcessingException e )
{
throw new RuntimeException( e );
}
}
}

Просмотреть файл

@ -0,0 +1,83 @@
// -----------------------------------------------------------------------
// <copyright file="CreateCustomerForIndirectReseller.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.indirectmodel;
import java.util.Random;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.Address;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.customers.CustomerBillingProfile;
import com.microsoft.store.partnercenter.models.customers.CustomerCompanyProfile;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Creates a new customer for an indirect reseller.
*/
public class CreateCustomerForIndirectReseller
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #CreateCustomerForIndirectReseller} class.
*
* @param context The scenario context.
*/
public CreateCustomerForIndirectReseller( IScenarioContext context )
{
super( "Create a new customer for an indirect reseller", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
String indirectResellerId = this.obtainIndirectResellerId("Enter the ID of the indirect reseller: ");
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
Address address = new Address();
address.setFirstName( "Gena" );
address.setLastName( "Soto" );
address.setAddressLine1( "One Microsoft Way" );
address.setCity( "Redmond" );
address.setState( "WA" );
address.setCountry( "US" );
address.setPostalCode( "98052" );
address.setPhoneNumber( "4255550101" );
CustomerBillingProfile billingProfile = new CustomerBillingProfile();
billingProfile.setCulture( "en-US" );
billingProfile.setEmail( "gena@wingtiptoys.com" );
billingProfile.setLanguage( "en" );
billingProfile.setCompanyName( "Wingtip Toys" + new Random().nextInt() );
billingProfile.setDefaultAddress( address );
CustomerCompanyProfile companyProfile = new CustomerCompanyProfile();
companyProfile.setDomain( "WingtipToys" + Math.abs( new Random().nextInt() ) + ".onmicrosoft.com" );
Customer customerToCreate = new Customer();
customerToCreate.setAssociatedPartnerId(indirectResellerId);
customerToCreate.setBillingProfile( billingProfile );
customerToCreate.setCompanyProfile( companyProfile );
this.getContext().getConsoleHelper().writeObject( customerToCreate, "New customer information" );
this.getContext().getConsoleHelper().startProgress( "Creating customer" );
Customer newCustomer = partnerOperations.getCustomers().create( customerToCreate );
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().success( "Success!" );
this.getContext().getConsoleHelper().writeObject( newCustomer, "Created customer information" );
}
}

Просмотреть файл

@ -0,0 +1,86 @@
// -----------------------------------------------------------------------
// <copyright file="GetCustomersOfIndirectReseller.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.indirectmodel;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.enumerators.IResourceCollectionEnumerator;
import com.microsoft.store.partnercenter.models.SeekBasedResourceCollection;
import com.microsoft.store.partnercenter.models.customers.Customer;
import com.microsoft.store.partnercenter.models.customers.CustomerSearchField;
import com.microsoft.store.partnercenter.models.query.IQuery;
import com.microsoft.store.partnercenter.models.query.QueryFactory;
import com.microsoft.store.partnercenter.models.query.filters.FieldFilterOperation;
import com.microsoft.store.partnercenter.models.query.filters.SimpleFieldFilter;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves the list of customers associated to an indirect reseller.
*/
public class GetCustomersOfIndirectReseller extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #CreateCustomerForIndirectReseller} class.
*
* @param context The scenario context.
*/
public GetCustomersOfIndirectReseller (IScenarioContext context)
{
super("Get customers of indirect reseller", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String indirectResellerId = this.obtainIndirectResellerId("Enter the ID of the indirect reseller: ");
this.getContext().getConsoleHelper().startProgress("Getting customers of the indirect reseller");
SimpleFieldFilter filter = new SimpleFieldFilter(
CustomerSearchField.INDIRECT_RESELLER.toString(),
FieldFilterOperation.STARTS_WITH,
indirectResellerId);
// Create an IQuery object to pass to the query method.
IQuery query = QueryFactory.getInstance().buildSimpleQuery(filter);
// Get the collection of matching customers.
SeekBasedResourceCollection<Customer> customersPage = partnerOperations.getCustomers().query(query);
this.getContext().getConsoleHelper().stopProgress();
// Create a customer enumerator which will aid us in traversing the customer pages.
IResourceCollectionEnumerator<SeekBasedResourceCollection<Customer>> customersEnumerator =
partnerOperations.getEnumerators().getCustomers().create(customersPage);
int pageNumber = 1;
while(customersEnumerator.hasValue())
{
// Print the current customer results page.
this.getContext().getConsoleHelper().writeObject(
customersEnumerator.getCurrent(), MessageFormat.format("Customer Page: {0}", pageNumber++));
System.out.println();
System.out.println("Press any key to retrieve the next customers page");
System.console().readLine();
this.getContext().getConsoleHelper().startProgress("Getting next customers page");
// Get the next page of customers.
customersEnumerator.next();
this.getContext().getConsoleHelper().stopProgress();
}
}
}

Просмотреть файл

@ -0,0 +1,42 @@
// -----------------------------------------------------------------------
// <copyright file="GetIndirectResellers.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.indirectmodel;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.relationships.PartnerRelationship;
import com.microsoft.store.partnercenter.models.relationships.PartnerRelationshipType;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves the list of indirect resellers associated to the indirect CSP partner.
*/
public class GetIndirectResellers extends BasePartnerScenario
{
public GetIndirectResellers (IScenarioContext context)
{
super("Get indirect resellers", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress("Getting indirect resellers");
ResourceCollection<PartnerRelationship> indirectResellers = partnerOperations.getRelationships().get(
PartnerRelationshipType.IS_INDIRECT_CLOUD_SOLUTION_PROVIDER_OF);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(indirectResellers, "Indirect Resellers");
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// -----------------------------------------------------------------------
// <copyright file="GetIndirectResellersOfCustomer.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.indirectmodel;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.relationships.PartnerRelationship;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that retrieves the list of indirect resellers associated to the indirect CSP partner of a customer.
*/
public class GetIndirectResellersOfCustomer extends BasePartnerScenario
{
public GetIndirectResellersOfCustomer (IScenarioContext context)
{
super("Get indirect resellers of a customer", context);
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer: ");
this.getContext().getConsoleHelper().startProgress("Getting indirect resellers of a customer");
ResourceCollection<PartnerRelationship> indirectResellers =
partnerOperations.getCustomers().byId(customerId).getRelationships().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(
indirectResellers,
MessageFormat.format( "Indirect Resellers of customer: {0}", customerId));
}
}

Просмотреть файл

@ -0,0 +1,56 @@
// -----------------------------------------------------------------------
// <copyright file="GetSubscriptionsByMpnId.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.indirectmodel;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.subscriptions.Subscription;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that gets a customer's subscriptions which belong to a partner MPN ID.
*/
public class GetSubscriptionsByMpnId
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetSubscriptionsByMpnId} class.
*
* @param context The scenario context.
*/
public GetSubscriptionsByMpnId( IScenarioContext context )
{
super( "Get customer subscriptions by partner MPN ID", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
String customerId = this.obtainCustomerId();
String partnerMpnId = this.obtainMpnId();
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting subscriptions" );
ResourceCollection<Subscription> customerSubscriptionsByMpnId =
partnerOperations.getCustomers().byId( customerId ).getSubscriptions().byPartner( partnerMpnId ).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(
customerSubscriptionsByMpnId,
MessageFormat.format(
"Customer subscriptions by Partner MPN ID: {0}",
partnerMpnId ) );
}
}

Просмотреть файл

@ -0,0 +1,93 @@
// -----------------------------------------------------------------------
// <copyright file="PlaceOrderForCustomer.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.indirectmodel;
import java.util.ArrayList;
import java.util.List;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.orders.Order;
import com.microsoft.store.partnercenter.models.orders.OrderLineItem;
import com.microsoft.store.partnercenter.models.relationships.PartnerRelationship;
import com.microsoft.store.partnercenter.models.relationships.PartnerRelationshipType;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that creates a new order for a customer with an indirect reseller.
*/
public class PlaceOrderForCustomer
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #PlaceOrderForCustomer} class.
*
* @param context The scenario context.
*/
public PlaceOrderForCustomer( IScenarioContext context )
{
super( "Create an order for a customer of an indirect reseller", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String customerId = this.obtainCustomerId("Enter the ID of the customer making the purchase");
String offerId = this.obtainOfferId("Enter the ID of the offer to purchase");
String indirectResellerId = this.obtainIndirectResellerId("Enter the ID of the indirect reseller: ");
this.getContext().getConsoleHelper().startProgress( "Getting list of indirect resellers" );
ResourceCollection<PartnerRelationship> indirectResellers = partnerOperations.getRelationships().get(
PartnerRelationshipType.IS_INDIRECT_CLOUD_SOLUTION_PROVIDER_OF);
this.getContext().getConsoleHelper().stopProgress();
PartnerRelationship partnerRelationship = null;
for (PartnerRelationship reseller : indirectResellers.getItems())
{
if(reseller.getId().equals(indirectResellerId))
{
partnerRelationship = reseller;
break;
}
}
OrderLineItem newOrderLineItem = new OrderLineItem();
newOrderLineItem.setFriendlyName("new offer purchase");
newOrderLineItem.setOfferId(offerId);
newOrderLineItem.setQuantity(5);
if(partnerRelationship != null)
{
newOrderLineItem.setPartnerIdOnRecord(partnerRelationship.getMpnId());
}
List<OrderLineItem> lineItems = new ArrayList<OrderLineItem>();
lineItems.add(newOrderLineItem);
Order order = new Order();
order.setLineItems(lineItems);
this.getContext().getConsoleHelper().writeObject(order, "Order to be placed");
this.getContext().getConsoleHelper().startProgress("Placing order");
Order createdOrder = partnerOperations.getCustomers().byId(customerId).getOrders().create(order);
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(createdOrder, "Created order");
}
}

Просмотреть файл

@ -0,0 +1,52 @@
// -----------------------------------------------------------------------
// <copyright file="VerifyPartnerMpnId.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.indirectmodel;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.partners.MpnProfile;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* A scenario that verifies a partner MPN ID.
*/
public class VerifyPartnerMpnId
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #VerifyPartnerMpnId} class.
*
* @param context The scenario context.
*/
public VerifyPartnerMpnId( IScenarioContext context )
{
super( "Verify partner MPN ID", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress( "Getting the logged in partner's profile" );
MpnProfile currentPartnerProfile = partnerOperations.getProfiles().getMpnProfile().get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( currentPartnerProfile, "Logged in partner profile" );
String partnerMpnId = this.obtainMpnId( "Enter the MPN ID to verify" );
this.getContext().getConsoleHelper().startProgress( MessageFormat.format( "Getting the partner profile for MPN ID: {0}",
partnerMpnId ) );
MpnProfile partnerProfile =
partnerOperations.getProfiles().getMpnProfile().get( partnerMpnId );
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( partnerProfile, "Partner profile" );
}
}

Просмотреть файл

@ -0,0 +1,44 @@
// -----------------------------------------------------------------------
// <copyright file="GetAccountBalance.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.invoice;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
/**
* Gets the account balance for a partner.
*/
public class GetAccountBalance
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetAccountBalance} class.
*
* @param context The scenario context.
*/
public GetAccountBalance( IScenarioContext context )
{
super( "Get account balance", context );
}
/**
* Executes the scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
this.getContext().getConsoleHelper().startProgress("Getting account balance");
// Getting the account balance
double accountBalance = partnerOperations.getInvoices().getSummary().get().getBalanceAmount();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject(accountBalance, "Account Balance");
}
}

Просмотреть файл

@ -0,0 +1,69 @@
// -----------------------------------------------------------------------
// <copyright file="GetInvoice.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.invoice;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.models.invoices.Invoice;
import com.microsoft.store.partnercenter.models.invoices.InvoiceDetail;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
import com.microsoft.store.partnercenter.samples.helpers.ConsoleHelper;
import com.microsoft.store.partnercenter.utils.StringHelper;
/**
* Gets a single partner invoice.
*/
public class GetInvoice
extends BasePartnerScenario
{
/**
* Initializes a new instance of the {@link #GetInvoice} class.
*
* @param context The scenario context.
*/
public GetInvoice( IScenarioContext context )
{
super( "Get partner's invoice details", context );
}
/**
* executes the get invoice scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String invoiceId = this.getContext().getConfiguration().getScenarioSettings().get( "DefaultInvoiceId" );
if ( StringHelper.isNullOrWhiteSpace( invoiceId ) )
{
// prompt the user the enter the invoice ID
invoiceId =
this.getContext().getConsoleHelper().readNonEmptyString( "Please enter the invoice ID to retrieve ",
"The invoice ID can't be empty" );
}
else
{
ConsoleHelper.getInstance().warning( MessageFormat.format( "Found Invoice ID: {0} in configuration.",
invoiceId ) );
}
this.getContext().getConsoleHelper().startProgress( "Retrieving invoice" );
// Retrieving invoice
Invoice invoice = partnerOperations.getInvoices().byId( invoiceId ).get();
this.getContext().getConsoleHelper().stopProgress();
this.getContext().getConsoleHelper().writeObject( invoice, "Invoice details" );
// Retrieving invoice line items
if ( invoice.getInvoiceDetails() != null )
{
for ( InvoiceDetail invoiceDetail : invoice.getInvoiceDetails() )
{
this.getContext().getConsoleHelper().writeObject( invoiceDetail, "Invoice Line Items" );
}
}
}
}

Просмотреть файл

@ -0,0 +1,109 @@
// -----------------------------------------------------------------------
// <copyright file="GetInvoiceLineItems.java" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
package com.microsoft.store.partnercenter.samples.invoice;
import java.text.MessageFormat;
import com.microsoft.store.partnercenter.IAggregatePartner;
import com.microsoft.store.partnercenter.enumerators.IResourceCollectionEnumerator;
import com.microsoft.store.partnercenter.invoices.IInvoice;
import com.microsoft.store.partnercenter.models.ResourceCollection;
import com.microsoft.store.partnercenter.models.invoices.Invoice;
import com.microsoft.store.partnercenter.models.invoices.InvoiceDetail;
import com.microsoft.store.partnercenter.models.invoices.InvoiceLineItem;
import com.microsoft.store.partnercenter.samples.BasePartnerScenario;
import com.microsoft.store.partnercenter.samples.IScenarioContext;
import com.microsoft.store.partnercenter.samples.helpers.ConsoleHelper;
import com.microsoft.store.partnercenter.utils.StringHelper;
/**
* Gets an invoice's line items.
*/
public class GetInvoiceLineItems
extends BasePartnerScenario
{
/**
* The invoice page size.
*/
private final int invoicePageSize;
/**
* Initializes a new instance of the {@link #GetInvoiceLineItems} class.
*
* @param context The scenario context.
* @param invoicePageSize The number of invoice line items to return per page.
*/
public GetInvoiceLineItems( IScenarioContext context, int invoicePageSize )
{
super( "Get an invoice's line items", context );
this.invoicePageSize = invoicePageSize;
}
/**
* executes the get invoice line items scenario.
*/
@Override
protected void runScenario()
{
IAggregatePartner partnerOperations = this.getContext().getUserPartnerOperations();
String invoiceId = this.getContext().getConfiguration().getScenarioSettings().get( "DefaultInvoiceId" );
if ( StringHelper.isNullOrWhiteSpace( invoiceId ) )
{
// prompt the user the enter the invoice ID
invoiceId =
this.getContext().getConsoleHelper().readNonEmptyString( "Please enter the ID of the invoice to retrieve ",
"The ID can't be empty" );
}
else
{
ConsoleHelper.getInstance().warning( MessageFormat.format( "Found Invoice ID: {0} in configuration.",
invoiceId ) );
}
this.getContext().getConsoleHelper().startProgress( "Retrieving Invoice Line Items" );
// Retrieve the invoice
IInvoice invoiceOperations = partnerOperations.getInvoices().byId( invoiceId );
Invoice invoice = invoiceOperations.get();
this.getContext().getConsoleHelper().stopProgress();
if ( ( invoice.getInvoiceDetails() == null ) || ( !invoice.getInvoiceDetails().iterator().hasNext() ) )
{
this.getContext().getConsoleHelper().warning( MessageFormat.format( "Invoice {0} does not have any invoice line items",
invoice.getId() ) );
}
else
{
for ( InvoiceDetail invoiceDetail : invoice.getInvoiceDetails() )
{
this.getContext().getConsoleHelper().startProgress( MessageFormat.format( "Getting invoice line item for product {0} and line item type {1}",
invoiceDetail.getBillingProvider(),
invoiceDetail.getInvoiceLineItemType() ) );
// Get the invoice line items
ResourceCollection<InvoiceLineItem> invoiceLineItemsCollection = invoicePageSize == 0
? invoiceOperations.by( invoiceDetail.getBillingProvider(),
invoiceDetail.getInvoiceLineItemType() ).get()
: invoiceOperations.by( invoiceDetail.getBillingProvider(),
invoiceDetail.getInvoiceLineItemType() ).get( invoicePageSize, 0 );
IResourceCollectionEnumerator<ResourceCollection<InvoiceLineItem>> invoiceLineItemEnumerator =
partnerOperations.getEnumerators().getInvoiceLineItems().create( invoiceLineItemsCollection );
this.getContext().getConsoleHelper().stopProgress();
int pageNumber = 1;
while ( invoiceLineItemEnumerator.hasValue() )
{
this.getContext().getConsoleHelper().writeObject( invoiceLineItemEnumerator.getCurrent(),
MessageFormat.format( "Invoice Line Item Page: {0}",
pageNumber++ ) );
ConsoleHelper.getInstance().warning( "\nPress Enter to retrieve the next invoice line items page" );
ConsoleHelper.getInstance().getScanner().nextLine();
this.getContext().getConsoleHelper().startProgress( "Getting next invoice line items page" );
// Get the next list of invoice line items
invoiceLineItemEnumerator.next();
this.getContext().getConsoleHelper().stopProgress();
}
}
}
}
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше