Skip to content

Remove partially done exercises content #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file modified configs/local/data/hypersonic/lportal.lobs
Binary file not shown.
4 changes: 2 additions & 2 deletions configs/local/data/hypersonic/lportal.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#HSQL Database Engine 2.7.1
#Tue Dec 17 18:30:29 GMT 2024
#Wed May 28 18:06:07 GMT 2025
modified=no
tx_timestamp=1833240
tx_timestamp=1926347
version=2.7.1
1,681 changes: 789 additions & 892 deletions configs/local/data/hypersonic/lportal.script

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class AccountCreationRequestProcessorService {
*/
@Autowired
public AccountCreationRequestProcessorService(
AccountCreationRequestQueueManager queueManager,
TaskExecutor taskExecutor) {
AccountCreationRequestQueueManager queueManager,
TaskExecutor taskExecutor) {

_queueManager = queueManager;
_taskExecutor = taskExecutor;
Expand Down Expand Up @@ -65,123 +65,102 @@ private void _processRequest(AccountCreationRequest request) {
try {
JSONObject jsonObject = new JSONObject(request.getAccountJSON());

JSONObject objectEntryDTODistributorApplicationJSONObject =
jsonObject.getJSONObject(
JSONObject objectEntryDTODistributorApplicationJSONObject = jsonObject.getJSONObject(
"objectEntryDTODistributorApplication");

JSONObject propertiesJSONObject =
objectEntryDTODistributorApplicationJSONObject.getJSONObject(
JSONObject propertiesJSONObject = objectEntryDTODistributorApplicationJSONObject.getJSONObject(
"properties");

String accountEmailAddress = propertiesJSONObject.getString(
"applicantEmailAddress");
"applicantEmailAddress");

String accountName = propertiesJSONObject.getString("businessName");

String accountExternalReferenceCode = "ACCOUNT_".concat(
accountName.toUpperCase(
).replace(
' ', '_'
));
accountName.toUpperCase().replace(
' ', '_'));

String tokenValue = request.getJwt(
).getTokenValue();
String tokenValue = request.getJwt().getTokenValue();

String authHeader = "Bearer " + tokenValue;

WebClient.Builder builder = WebClient.builder();

WebClient webClient = builder.baseUrl(
lxcDXPServerProtocol + "://" + lxcDXPMainDomain
).defaultHeader(
HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE
).defaultHeader(
HttpHeaders.AUTHORIZATION, authHeader
).defaultHeader(
HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE
).build();

webClient.post(
).uri(
"o/headless-admin-user/v1.0/accounts"
).bodyValue(
StringBundler.concat(
"{\"externalReferenceCode\": \"",
accountExternalReferenceCode, "\", \"name\": \"",
accountName, "\", \"type\": \"business\"}")
).retrieve(
).toEntity(
String.class
).flatMap(
responseEntity -> _transform(responseEntity)
).doOnSuccess(
responseEntity -> _log(
"Created account: " + responseEntity.getBody())
).then(
webClient.post(
).uri(
StringBundler.concat(
"o/headless-admin-user/v1.0/accounts",
"/by-external-reference-code/",
accountExternalReferenceCode,
"/user-accounts/by-email-address/", accountEmailAddress)
).retrieve(
).toEntity(
String.class
).flatMap(
responseEntity -> _transform(responseEntity)
)
).doOnSuccess(
responseEntity -> _log(
"Assigned user: " + responseEntity.getBody())
).then(
webClient.get(
).uri(
uriBuilder -> uriBuilder.path(
StringBundler.concat(
"o/headless-admin-user/v1.0/accounts",
"/by-external-reference-code/",
accountExternalReferenceCode, "/account-roles")
).queryParam(
"filter", "name eq 'Account Administrator'"
).build()
).retrieve(
).bodyToMono(
String.class
).map(
pageJSON -> new JSONObject(
pageJSON
).getJSONArray(
"items"
).getJSONObject(
0
).getInt(
"id"
)
)
).flatMap(
accountRoleId -> webClient.post(
).uri(
StringBundler.concat(
"o/headless-admin-user/v1.0/accounts",
"/by-external-reference-code/",
accountExternalReferenceCode, "/account-roles/",
accountRoleId, "/user-accounts/by-email-address/",
accountEmailAddress)
).retrieve(
).toEntity(
String.class
).flatMap(
responseEntity -> _transform(responseEntity)
).doOnSuccess(
responseEntity -> _log(
"Assigned role: " + responseEntity.getBody())
)
).subscribe();
}
catch (Exception exception) {
lxcDXPServerProtocol + "://" + lxcDXPMainDomain).defaultHeader(
HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(
HttpHeaders.AUTHORIZATION, authHeader)
.defaultHeader(
HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();

webClient.post().uri(
"o/headless-admin-user/v1.0/accounts").bodyValue(
StringBundler.concat(
"{\"externalReferenceCode\": \"",
accountExternalReferenceCode, "\", \"name\": \"",
accountName, "\", \"type\": \"business\"}"))
.retrieve().toEntity(
String.class)
.flatMap(
responseEntity -> _transform(responseEntity))
.doOnSuccess(
responseEntity -> _log(
"Created account: " + responseEntity.getBody()))
.then(
webClient.post().uri(
StringBundler.concat(
"o/headless-admin-user/v1.0/accounts",
"/by-external-reference-code/",
accountExternalReferenceCode,
"/user-accounts/by-email-address/", accountEmailAddress))
.retrieve().toEntity(
String.class)
.flatMap(
responseEntity -> _transform(responseEntity)))
.doOnSuccess(
responseEntity -> _log(
"Assigned user: " + responseEntity.getBody()))
.then(
webClient.get().uri(
uriBuilder -> uriBuilder.path(
StringBundler.concat(
"o/headless-admin-user/v1.0/accounts",
"/by-external-reference-code/",
accountExternalReferenceCode, "/account-roles"))
.queryParam(
"filter", "name eq 'Account Administrator'")
.build())
.retrieve().bodyToMono(
String.class)
.map(
pageJSON -> new JSONObject(
pageJSON).getJSONArray(
"items")
.getJSONObject(
0)
.getInt(
"id")))
.flatMap(
accountRoleId -> webClient.post().uri(
StringBundler.concat(
"o/headless-admin-user/v1.0/accounts",
"/by-external-reference-code/",
accountExternalReferenceCode, "/account-roles/",
accountRoleId, "/user-accounts/by-email-address/",
accountEmailAddress))
.retrieve().toEntity(
String.class)
.flatMap(
responseEntity -> _transform(responseEntity))
.doOnSuccess(
responseEntity -> _log(
"Assigned role: " + responseEntity.getBody())))
.subscribe();
} catch (Exception exception) {
_log.error(
"Failed to process account: {}", request.getAccountJSON(), exception);
"Failed to process account: {}", request.getAccountJSON(), exception);
}
}

Expand All @@ -190,35 +169,31 @@ private void _processRequest(AccountCreationRequest request) {
*/
private void _startProcessing() {
_taskExecutor.execute(
() -> {
while (true) {
try {
_queueManager.awaitWork(); // Wait for work if the queue is empty

while (!_queueManager.isEmpty()) {
AccountCreationRequest request =
_queueManager.dequeue();

_processRequest(request);
() -> {
while (true) {
try {
_queueManager.awaitWork(); // Wait for work if the queue is empty

while (!_queueManager.isEmpty()) {
AccountCreationRequest request = _queueManager.dequeue();

_processRequest(request);
}
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();

_log.error(
"Queue processing interrupted",
interruptedException);
} catch (Exception exception) {
_log.error("Error processing queue entry", exception);
}
}
catch (InterruptedException interruptedException) {
Thread.currentThread(
).interrupt();

_log.error(
"Queue processing interrupted",
interruptedException);
}
catch (Exception exception) {
_log.error("Error processing queue entry", exception);
}
}
});
});
}

private Mono<ResponseEntity<String>> _transform(
ResponseEntity<String> responseEntity) {
ResponseEntity<String> responseEntity) {

HttpStatus httpStatus = responseEntity.getStatusCode();

Expand All @@ -230,7 +205,7 @@ private Mono<ResponseEntity<String>> _transform(
}

private static final Logger _log = LoggerFactory.getLogger(
AccountCreationRequestProcessorService.class);
AccountCreationRequestProcessorService.class);

private final AccountCreationRequestQueueManager _queueManager;
private final TaskExecutor _taskExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class AccountCreationRequestQueueManager {
/**
* Waits for work to be available.
*
* @throws InterruptedException if the thread is interrupted while waiting for work
* @throws InterruptedException if the thread is interrupted while waiting for
* work
*/
public void awaitWork() throws InterruptedException {
_lock.lock();
Expand All @@ -27,8 +28,7 @@ public void awaitWork() throws InterruptedException {
while (isEmpty()) {
_notEmpty.await(); // Wait until notified
}
}
finally {
} finally {
_lock.unlock();
}
}
Expand All @@ -37,7 +37,8 @@ public void awaitWork() throws InterruptedException {
* Dequeues an account creation request.
*
* @return the account creation request
* @throws InterruptedException if the thread is interrupted while waiting for an account creation request
* @throws InterruptedException if the thread is interrupted while waiting for
* an account creation request
*/
public AccountCreationRequest dequeue() throws InterruptedException {

Expand Down Expand Up @@ -79,15 +80,13 @@ private void _signalExecutor() {

try {
_notEmpty.signal(); // Notify the executor that work is available
}
finally {
} finally {
_lock.unlock();
}
}

private final ReentrantLock _lock = new ReentrantLock();
private final Condition _notEmpty = _lock.newCondition();
private final BlockingQueue<AccountCreationRequest> _queue =
new LinkedBlockingQueue<>();
private final BlockingQueue<AccountCreationRequest> _queue = new LinkedBlockingQueue<>();

}
3 changes: 1 addition & 2 deletions exercises/module-2/action-classes/BaseRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ protected void log(Jwt jwt, Log log, String json) {
JSONObject jsonObject = new JSONObject(json);

log.info("JSON: " + jsonObject.toString(4));
}
catch (Exception exception) {
} catch (Exception exception) {
log.error("JSON: " + json, exception);
}

Expand Down
6 changes: 3 additions & 3 deletions exercises/module-2/action-classes/TaskExecutorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
* Creates the task executor which will be processing the account creation requests.
* Creates the task executor which will be processing the account creation
* requests.
*
* @author dnebing
*/
Expand All @@ -18,8 +19,7 @@ public TaskExecutor taskExecutor() {

// create a thread pool for the task executor

ThreadPoolTaskExecutor threadPoolTaskExecutor =
new ThreadPoolTaskExecutor();
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();

// initialize to some reasonable values

Expand Down