Skip to content

Commit f5de1c8

Browse files
committed
MLE-21542 More Polaris fixes
1 parent f3517b0 commit f5de1c8

File tree

21 files changed

+96
-49
lines changed

21 files changed

+96
-49
lines changed

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ protected String convertXmlPayloadToJsonIfNecessary(CommandContext context, Stri
272272
if (resourceMapper == null) {
273273
resourceMapper = new DefaultResourceMapper(new API(context.getManageClient()));
274274
}
275-
return resourceMapper.readResource(payload, resourceClassType).getJson();
275+
Resource resource = resourceMapper.readResource(payload, resourceClassType);
276+
Objects.requireNonNull(resource);
277+
return resource.getJson();
276278
}
277279

278280
/**

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/databases/DeployOtherDatabasesCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ protected List<DatabasePlan> mergeDatabasePlanFiles(CommandContext context, Data
285285
String testPayload = payloadTokenReplacer.replaceTokens(copyFileToString(files.get(0)), context.getAppConfig(), true);
286286
testDatabasePlan.setPayload(testPayload);
287287
Database testDb = resourceMapper.readResource(payload, Database.class);
288+
Objects.requireNonNull(testDb);
288289
testDb.setDatabaseName(testContentDatabaseName);
289290
testDatabasePlan.setDatabaseForSorting(testDb);
290291
}

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/forests/ForestBuilder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
import com.marklogic.mgmt.mapper.DefaultResourceMapper;
2323
import com.marklogic.mgmt.mapper.ResourceMapper;
2424

25-
import java.util.ArrayList;
26-
import java.util.LinkedHashMap;
27-
import java.util.List;
28-
import java.util.Map;
25+
import java.util.*;
2926

3027
/**
3128
* Based on a given ForestPlan object, builds a list of one or more Forest objects in memory - i.e. nothing is written
@@ -60,6 +57,8 @@ public ForestBuilder(ForestNamingStrategy forestNamingStrategy) {
6057
*/
6158
public List<Forest> buildForests(ForestPlan forestPlan, AppConfig appConfig) {
6259
final String databaseName = forestPlan.getDatabaseName();
60+
Objects.requireNonNull(databaseName);
61+
Objects.requireNonNull(appConfig);
6362

6463
// Find out what forests we have already, keyed on host and then data directory
6564
Map<String, Map<String, List<Forest>>> existingForestsMap = existingForestsMap(forestPlan);

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/plugins/InstallPluginsCommand.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,18 @@ protected void installPluginsInPath(String path, AppConfig appConfig, DatabaseCl
9090
return;
9191
}
9292

93-
for (File dir : new File(path).listFiles()) {
94-
if (!dir.isDirectory()) {
95-
continue;
96-
}
93+
File[] files = new File(path).listFiles();
94+
if (files != null) {
95+
for (File dir : files) {
96+
if (!dir.isDirectory()) {
97+
continue;
98+
}
9799

98-
makePlugin(dir, appConfig);
99-
final String binaryUri = insertPluginZip(dir, appConfig, client);
100-
if (binaryUri != null) {
101-
installPlugin(binaryUri, appConfig, client);
100+
makePlugin(dir, appConfig);
101+
final String binaryUri = insertPluginZip(dir, appConfig, client);
102+
if (binaryUri != null) {
103+
installPlugin(binaryUri, appConfig, client);
104+
}
102105
}
103106
}
104107
}

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/schemas/LoadSchemasCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected String findContentDatabaseAssociatedWithSchemasDatabase(CommandContext
164164
String payload = copyFileToString(f, context);
165165
try {
166166
Database db = resourceMapper.readResource(payload, Database.class);
167-
if (schemasDatabaseName.equals(db.getSchemaDatabase())) {
167+
if (db != null && schemasDatabaseName != null && schemasDatabaseName.equals(db.getSchemaDatabase())) {
168168
tdeValidationDatabase = db.getDatabaseName();
169169
break;
170170
}

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/security/DeployPrivilegeRolesCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected String adjustPayloadBeforeSavingResource(CommandContext context, File
6868
resourceMapper = new DefaultResourceMapper(new API(context.getManageClient()));
6969
}
7070
Privilege p = resourceMapper.readResource(payload, Privilege.class);
71-
if (p.getRole() == null || p.getRole().isEmpty()) {
71+
if (p == null || p.getRole() == null || p.getRole().isEmpty()) {
7272
return null;
7373
}
7474
}

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/viewschemas/DeployViewSchemasCommand.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,17 @@ protected ResourceManager getResourceManager(CommandContext context) {
8888
protected void afterResourceSaved(ResourceManager mgr, CommandContext context, ResourceReference reference, SaveReceipt receipt) {
8989
if (reference != null) {
9090
File resourceFile = reference.getLastFile();
91-
PayloadParser parser = new PayloadParser();
92-
String viewSchemaName = parser.getPayloadFieldValue(receipt.getPayload(), "view-schema-name");
93-
File parentFile = resourceFile.getParentFile();
94-
if (parentFile != null) {
95-
File viewDir = new File(parentFile, viewSchemaName + "-views");
96-
if (viewDir.exists()) {
97-
ViewManager viewMgr = new ViewManager(context.getManageClient(), currentDatabaseIdOrName, viewSchemaName);
98-
for (File viewFile : listFilesInDirectory(viewDir)) {
99-
saveResource(viewMgr, context, viewFile);
91+
if (resourceFile != null) {
92+
PayloadParser parser = new PayloadParser();
93+
String viewSchemaName = parser.getPayloadFieldValue(receipt.getPayload(), "view-schema-name");
94+
File parentFile = resourceFile.getParentFile();
95+
if (parentFile != null) {
96+
File viewDir = new File(parentFile, viewSchemaName + "-views");
97+
if (viewDir.exists()) {
98+
ViewManager viewMgr = new ViewManager(context.getManageClient(), currentDatabaseIdOrName, viewSchemaName);
99+
for (File viewFile : listFilesInDirectory(viewDir)) {
100+
saveResource(viewMgr, context, viewFile);
101+
}
100102
}
101103
}
102104
}

ml-app-deployer/src/main/java/com/marklogic/mgmt/ManageClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ public HttpEntity<String> buildXmlEntity(String xml) {
269269

270270
protected void logRequest(String path, String contentType, String method) {
271271
if (logger.isInfoEnabled()) {
272-
String username = manageConfig != null ?
273-
String.format("as user '%s' ", manageConfig.getUsername()) : "";
272+
String username = String.format("as user '%s' ", manageConfig.getUsername());
274273
logger.info("Sending {} {} request {}to path: {}", contentType, method, username, buildUri(path));
275274
}
276275
}

ml-app-deployer/src/main/java/com/marklogic/mgmt/resource/forests/ForestManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.marklogic.mgmt.mapper.ResourceMapper;
2626
import com.marklogic.mgmt.resource.AbstractResourceManager;
2727
import com.marklogic.rest.util.Fragment;
28+
import com.marklogic.rest.util.XPathUtil;
2829
import org.springframework.http.HttpMethod;
2930
import org.springframework.web.util.UriComponentsBuilder;
3031

@@ -162,8 +163,9 @@ public void createJsonForest(String json) {
162163

163164
public boolean forestExists(String nameOrId) {
164165
Fragment f = getManageClient().getXml("/manage/v2/forests");
165-
return f.elementExists(format("/node()/f:list-items/f:list-item[f:nameref = '%s' or f:idref = '%s']", nameOrId,
166-
nameOrId));
166+
String valueForXPath = XPathUtil.sanitizeValueForXPathExpression(nameOrId);
167+
return f.elementExists(format("/node()/f:list-items/f:list-item[f:nameref = '%s' or f:idref = '%s']", valueForXPath,
168+
valueForXPath));
167169
}
168170

169171
public void attachForest(String forestIdOrName, String databaseIdOrName) {

ml-app-deployer/src/main/java/com/marklogic/mgmt/resource/mimetypes/MimetypeManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.marklogic.mgmt.mapper.ResourceMapper;
2424
import com.marklogic.mgmt.resource.AbstractResourceManager;
2525

26+
import java.util.Objects;
27+
2628
public class MimetypeManager extends AbstractResourceManager {
2729

2830
private boolean updateWhenPropertiesAreEqual = false;
@@ -63,6 +65,7 @@ public SaveReceipt updateResource(String payload, String resourceId) {
6365
}
6466

6567
Mimetype incomingMimetype = resourceMapper.readResource(payload, Mimetype.class);
68+
Objects.requireNonNull(incomingMimetype);
6669
final String name = incomingMimetype.getName();
6770

6871
String existingJson = super.getPropertiesAsJson(name);

0 commit comments

Comments
 (0)