-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Stefan Maute <stefan.maute@bosch-si.com>
- Loading branch information
Stefan Maute
committed
Nov 28, 2018
1 parent
9f31e69
commit f4294bf
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
.../cache/src/main/java/org/eclipse/ditto/services/concierge/cache/PolicyCommandFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2017-2018 Bosch Software Innovations GmbH. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/org/documents/epl-2.0/index.php | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.services.concierge.cache; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.ditto.model.base.headers.DittoHeaders; | ||
import org.eclipse.ditto.services.models.policies.commands.sudo.SudoRetrievePolicy; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.slf4j.MDC; | ||
|
||
/** | ||
* Creates commands to access the Policies service. | ||
*/ | ||
final class PolicyCommandFactory { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(PolicyCommandFactory.class); | ||
|
||
private PolicyCommandFactory() { | ||
throw new AssertionError(); | ||
} | ||
|
||
/** | ||
* Creates a sudo command for retrieving a policy. | ||
* | ||
* @param policyId the policyId. | ||
* @return the created command. | ||
*/ | ||
static SudoRetrievePolicy sudoRetrievePolicy(final String policyId) { | ||
return SudoRetrievePolicy.of(policyId, | ||
DittoHeaders.newBuilder().correlationId(getCorrelationId(policyId)).build()); | ||
} | ||
|
||
private static String getCorrelationId(final String policyId) { | ||
String correlationId = MDC.get("x-correlation-id"); | ||
if (null == correlationId) { | ||
correlationId = UUID.randomUUID().toString(); | ||
LOGGER.debug("Found no correlation-id for SudoRetrievePolicy on Policy <{}>. Using new correlation-id: {}", | ||
policyId, correlationId); | ||
return correlationId; | ||
} else { | ||
LOGGER.debug("Found correlation-id [{}] in MDC for SudoRetrievePolicy on Policy <{}>. ", correlationId, policyId); | ||
return correlationId; | ||
} | ||
} | ||
|
||
} |