Skip to content

Commit

Permalink
Merge pull request #1002 from hashmapinc/Tempus-957-Unit-System-Support
Browse files Browse the repository at this point in the history
Tempus 957 unit system support
  • Loading branch information
akshaymhetre committed Jan 11, 2019
2 parents 6c7375a + 21dd726 commit 86dd62a
Show file tree
Hide file tree
Showing 24 changed files with 552 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,38 @@ public void testFindTenantsByTitle() throws Exception {
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}

@Test
public void testSaveAndGetUnitSystem() throws Exception {
loginTenantAdmin();
doPost("/api/unit-system/tenant/"+ tenantAdmin.getTenantId(), "UK",String.class);
String unitSystem = doGet("/api/unit-system/tenant/"+ tenantAdmin.getTenantId(), String.class);
Assert.assertEquals("{\"unit_system\":\"UK\"}", unitSystem);
}

@Test
public void testUpdateUnitSystem() throws Exception {
loginTenantAdmin();
doPost("/api/unit-system/tenant/"+ tenantAdmin.getTenantId(), "UK",String.class);
doPost("/api/unit-system/tenant/"+ tenantAdmin.getTenantId(), "SI",String.class);
String unitSystem = doGet("/api/unit-system/tenant/"+ tenantAdmin.getTenantId(), String.class);
Assert.assertEquals("{\"unit_system\":\"SI\"}", unitSystem);
}

@Test
public void testGetDefaultUnitSystem() throws Exception {
loginTenantAdmin();
String unitSystem = doGet("/api/unit-system/tenant/"+ tenantAdmin.getTenantId(), String.class);
Assert.assertEquals("{\"unit_system\":\"SI\"}", unitSystem);
}

@Test
public void testGetUnitSystemForCustomerUser() throws Exception {
loginTenantAdmin();
doPost("/api/unit-system/tenant/"+ tenantAdmin.getTenantId(), "UK",String.class);
logout();
loginCustomerUser();
String unitSystem = doGet("/api/unit-system/tenant/"+ customerUser.getTenantId(), String.class);
Assert.assertEquals("{\"unit_system\":\"UK\"}", unitSystem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public SharedPluginProcessingContext(ActorSystemContext sysContext, TenantId ten
this.tenantService = sysContext.getTenantService();
this.relationService = sysContext.getRelationService();
this.auditLogService = sysContext.getAuditLogService();
unitConversionService = sysContext.getUnitConversionService();
this.unitConversionService = sysContext.getUnitConversionService();
}

public PluginId getPluginId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,35 @@ public TextPageData<Tenant> getTenants(@RequestParam int limit,
throw handleException(e);
}
}

@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@GetMapping(value = "/unit-system/tenant/{tenantId}")
@ResponseBody
public String getUserUnitSystem(@PathVariable("tenantId") String strUserId) throws TempusException {
checkParameter("tenantId", strUserId);
try {
TenantId tenantId = new TenantId(toUUID(strUserId));
checkTenantId(tenantId);
return tenantService.findUnitSystemByTenantId(tenantId);

} catch (Exception e) {
throw handleException(e);
}
}

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@PostMapping(value = "/unit-system/tenant/{tenantId}")
@ResponseBody
public void saveUserUnitSystem(@PathVariable("tenantId") String strUserId, @RequestBody String unitSystem) throws TempusException {
checkParameter("tenantId", strUserId);
try {
TenantId tenantId = new TenantId(toUUID(strUserId));
checkTenantId(tenantId);
tenantService.saveUnitSystem(unitSystem, tenantId);

} catch (Exception e) {
throw handleException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
*/
package com.hashmapinc.server.controller;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.hashmapinc.server.common.data.Logo;
import com.hashmapinc.server.common.data.Tenant;
import com.hashmapinc.server.common.data.Theme;
import com.hashmapinc.server.common.data.UserSettings;
import com.hashmapinc.server.common.data.*;
import com.hashmapinc.server.common.data.id.UserId;
import com.hashmapinc.server.common.data.security.Authority;
import com.hashmapinc.server.dao.logo.LogoService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.hashmapinc.server.dao.service;

import com.hashmapinc.server.common.data.UUIDConverter;
import com.hashmapinc.server.common.data.id.TenantId;
import com.hashmapinc.server.common.data.page.TextPageData;
import com.hashmapinc.server.common.data.page.TextPageLink;
import org.apache.commons.lang3.RandomStringUtils;
Expand Down Expand Up @@ -201,4 +203,46 @@ public void testFindTenantsByTitle() {
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}

@Test
public void testSaveUserUnitSystem() {
TenantId tenantId = new TenantId(UUIDConverter.fromString("1e7461259eab8808080808080808080"));
tenantService.saveUnitSystem("UK", tenantId);
String unitSystem = tenantService.findUnitSystemByTenantId(tenantId);
Assert.assertEquals("{\"unit_system\":\"UK\"}", unitSystem);
Assert.assertNotNull(unitSystem);
tenantService.deleteUnitSystemByTenantId(tenantId);
}

@Test
public void testFindUnitSystemByUserId() {
TenantId tenantId = new TenantId(UUIDConverter.fromString("1e7461259eab8808080808080808080"));
tenantService.saveUnitSystem("UK", tenantId);
String unitSystemByUserId = tenantService.findUnitSystemByTenantId(tenantId);
Assert.assertNotNull(unitSystemByUserId);
Assert.assertEquals("{\"unit_system\":\"UK\"}", unitSystemByUserId);
tenantService.deleteUnitSystemByTenantId(tenantId);
}

@Test
public void testFindUnitSystemByUserIdNotPresentShouldReturnSi() {
String unitSystemByUserId = tenantService.findUnitSystemByTenantId(new TenantId(UUIDConverter.fromString("1e7461259eab8808080808080818181")));
Assert.assertNotNull(unitSystemByUserId);
Assert.assertEquals("{\"unit_system\":\"SI\"}", unitSystemByUserId);
}

@Test
public void testUpdateUnitSystemByUserId() {
TenantId tenantId = new TenantId(UUIDConverter.fromString("1e7461259eab8808080808081818181"));
tenantService.saveUnitSystem("UK", tenantId);
String unitSystemByUserId = tenantService.findUnitSystemByTenantId(tenantId);
Assert.assertNotNull(unitSystemByUserId);
Assert.assertEquals("{\"unit_system\":\"UK\"}", unitSystemByUserId);

tenantService.saveUnitSystem("US", tenantId);
String updatedUnitSystem = tenantService.findUnitSystemByTenantId(tenantId);
Assert.assertNotNull(updatedUnitSystem);
Assert.assertEquals("{\"unit_system\":\"US\"}", updatedUnitSystem);
tenantService.deleteUnitSystemByTenantId(tenantId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.hashmapinc.server.dao.service;

import com.datastax.driver.core.utils.UUIDs;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.hashmapinc.server.common.data.UUIDConverter;
Expand All @@ -25,11 +24,9 @@
import com.hashmapinc.server.common.data.id.UserId;
import com.hashmapinc.server.common.data.security.Authority;
import com.hashmapinc.server.dao.exception.DataValidationException;
import com.hashmapinc.server.dao.settings.UserSettingsDao;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class BaseUserSettingsServiceTest extends AbstractServiceTest {

Expand Down
3 changes: 2 additions & 1 deletion dao/src/it/resources/sql/drop-all-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ DROP TABLE IF EXISTS data_model;
DROP TABLE IF EXISTS kubeless_computation_meta_data;
DROP TABLE IF EXISTS metadata_entries;
DROP TABLE IF EXISTS spark_computation_meta_data;
DROP TABLE IF EXISTS tempus_gateway_configuration;
DROP TABLE IF EXISTS tempus_gateway_configuration;
DROP TABLE IF EXISTS tenant_unit_system;
Loading

0 comments on commit 86dd62a

Please sign in to comment.