Skip to content

Commit

Permalink
Merge pull request #157 from Open-MBEE/develop
Browse files Browse the repository at this point in the history
4.0.3
  • Loading branch information
dlamoris authored Feb 24, 2021
2 parents 80caf2d + 949cbfc commit 8bbebde
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 9 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ subprojects {
signing {
if (project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')) {
sign publishing.publications.mavenJava
} else if (project.hasProperty('signingKey') && project.hasProperty('signingPassword')) {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.mavenJava
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import org.openmbee.mms.core.dao.ProjectDAO;
import org.openmbee.mms.core.exceptions.BadRequestException;
import org.openmbee.mms.core.exceptions.ConflictException;
import org.openmbee.mms.core.exceptions.DeletedException;
import org.openmbee.mms.core.exceptions.ForbiddenException;
import org.openmbee.mms.core.exceptions.InternalErrorException;
import org.openmbee.mms.core.exceptions.NotFoundException;
import org.openmbee.mms.core.exceptions.NotModifiedException;
import org.openmbee.mms.core.exceptions.UnauthorizedException;
Expand Down Expand Up @@ -95,8 +97,12 @@ protected void handleSingleResponse(BaseResponse res) {
throw new ForbiddenException(res);
case 404:
throw new NotFoundException(res);
case 409:
throw new ConflictException(res);
case 410:
throw new DeletedException(res);
case 500:
throw new InternalErrorException(res);
default:
break;
}
Expand Down
86 changes: 86 additions & 0 deletions example/crud.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -3477,6 +3477,92 @@
}
},
"response": []
},
{
"name": "create branch with long id",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"refs\": [\n\t\t{\n\t\t\t\"name\": \"long\",\n \"id\": \"a123456789012345678901234567890123456789012345678901234567890\"\n\t\t}\n\t]\n}"
},
"url": {
"raw": "{{host}}/projects/aa/refs",
"host": [
"{{host}}"
],
"path": [
"projects",
"aa",
"refs"
]
}
},
"response": []
},
{
"name": "post to long branch",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"name\": \"blah\",\n\t\t\t\"id\": \"blah\"\n\t\t}\n\t]\n}"
},
"url": {
"raw": "{{host}}/projects/aa/refs/a123456789012345678901234567890123456789012345678901234567890/elements",
"host": [
"{{host}}"
],
"path": [
"projects",
"aa",
"refs",
"a123456789012345678901234567890123456789012345678901234567890",
"elements"
]
}
},
"response": []
}
],
"auth": {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=4.0.2
version=4.0.3
group=org.openmbee.mms

springBootVersion=2.2.6.RELEASE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.openmbee.mms.rdb.config;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand Down Expand Up @@ -158,11 +162,11 @@ public void copyTablesFromParent(String target, String parent, String parentComm
return;
}

final String targetNodeTable = String.format("nodes%s", target);
final String targetNodeTable = String.format("nodes%s", getNodeTableName(target));
StringBuilder parentNodeTable = new StringBuilder("nodes");

if (parent != null && !parent.equalsIgnoreCase("master")) {
parentNodeTable.append(String.format("%s", parent));
parentNodeTable.append(String.format("%s", getNodeTableName(parent)));
}

JdbcTemplate jdbcTemplate = new JdbcTemplate(
Expand Down Expand Up @@ -203,4 +207,29 @@ private Map<String, Object> getSchemaProperties() {

return properties;
}

/**
* Returns the suffix that should be appended to 'nodes' table given refId
* Empty for 'master', lowercased refId if refId.length <= 50, SHA-1 hash of refId otherwise
*
* @param refId
* @return
*/
static public String getNodeTableName(String refId) {
String res = refId;
if (refId.equals(ContextObject.MASTER_BRANCH)) {
res = "";
} else if (refId.length() <= 50) {
res = refId.toLowerCase();
} else {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-1");
byte[] encodedhash = digest.digest(refId.getBytes(StandardCharsets.UTF_8));
res = new BigInteger(1, encodedhash).toString(16).toLowerCase();
} catch (NoSuchAlgorithmException e) {
res = refId.toLowerCase().substring(0, 50);
}
}
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.openmbee.mms.core.config.ContextHolder;
import org.openmbee.mms.core.config.ContextObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -33,7 +32,7 @@ public Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment jdbcEn
@Override
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
String refId = ContextHolder.getContext().getBranchId();
refId = refId.equals(ContextObject.MASTER_BRANCH) ? "" : refId.toLowerCase();
refId = DatabaseDefinitionService.getNodeTableName(refId);
return new Identifier(compoundKey(name.getText(), refId), name.isQuoted());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.openmbee.mms.rdb.repositories;

import org.openmbee.mms.core.config.ContextHolder;
import org.openmbee.mms.core.config.ContextObject;
import org.openmbee.mms.core.exceptions.BadRequestException;
import org.openmbee.mms.rdb.config.DatabaseDefinitionService;
import org.openmbee.mms.rdb.datasources.CrudDataSources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -38,10 +39,10 @@ public JdbcTemplate getConn() {

public String getSuffix() {
String refId = ContextHolder.getContext().getBranchId();
if(BRANCH_ID_VALID_PATTERN.matcher(refId).matches()) {
return refId.equals(ContextObject.MASTER_BRANCH) ? "" : refId.toLowerCase();
if (BRANCH_ID_VALID_PATTERN.matcher(refId).matches()) {
return DatabaseDefinitionService.getNodeTableName(refId);
} else {
throw new IllegalArgumentException("Bad branch id, aborting current operation.");
throw new BadRequestException("Bad branch id, aborting current operation.");
}
}
}

0 comments on commit 8bbebde

Please sign in to comment.