-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into tempus-elaboration-37
- Loading branch information
Showing
38 changed files
with
1,106 additions
and
14 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
application/src/main/java/com/hashmapinc/server/controller/DataModelController.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,52 @@ | ||
/** | ||
* Copyright © 2017-2018 Hashmap, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hashmapinc.server.controller; | ||
|
||
import com.hashmapinc.server.common.data.DataModel; | ||
import com.hashmapinc.server.common.data.EntityType; | ||
import com.hashmapinc.server.common.data.audit.ActionType; | ||
import com.hashmapinc.server.exception.TempusException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@Slf4j | ||
public class DataModelController extends BaseController { | ||
|
||
public static final String DATA_MODEL_ID = "dataModelId"; | ||
|
||
@PreAuthorize("hasAuthority('TENANT_ADMIN')") | ||
@RequestMapping(value = "/data-model", method = RequestMethod.POST) | ||
@ResponseBody | ||
public DataModel saveDataModel(@RequestBody DataModel dataModel) throws TempusException { | ||
dataModel.setTenantId(getCurrentUser().getTenantId()); | ||
dataModel.setLastUpdatedTs(System.currentTimeMillis()); | ||
try { | ||
DataModel savedDataModel = checkNotNull(dataModelService.saveDataModel(dataModel)); | ||
logEntityAction(savedDataModel.getId(), savedDataModel, | ||
null, | ||
dataModel.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); | ||
return savedDataModel; | ||
} catch (Exception e) { | ||
logEntityAction(emptyId(EntityType.DATA_MODEL), dataModel, | ||
null, dataModel.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e); | ||
throw handleException(e); | ||
} | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
application/src/test/java/com/hashmapinc/server/controller/BaseDataModelControllerTest.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,77 @@ | ||
/** | ||
* Copyright © 2017-2018 Hashmap, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hashmapinc.server.controller; | ||
|
||
import com.hashmapinc.server.common.data.DataModel; | ||
import com.hashmapinc.server.common.data.Tenant; | ||
import com.hashmapinc.server.common.data.User; | ||
import com.hashmapinc.server.common.data.security.Authority; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
public class BaseDataModelControllerTest extends AbstractControllerTest { | ||
|
||
private Tenant savedTenant; | ||
private User tenantAdmin; | ||
|
||
@Before | ||
public void beforeTest() throws Exception { | ||
loginSysAdmin(); | ||
|
||
Tenant tenant = new Tenant(); | ||
tenant.setTitle("My tenant"); | ||
savedTenant = doPost("/api/tenant", tenant, Tenant.class); | ||
Assert.assertNotNull(savedTenant); | ||
|
||
tenantAdmin = new User(); | ||
tenantAdmin.setAuthority(Authority.TENANT_ADMIN); | ||
tenantAdmin.setTenantId(savedTenant.getId()); | ||
tenantAdmin.setEmail("[email protected]"); | ||
tenantAdmin.setFirstName("Joe"); | ||
tenantAdmin.setLastName("Downs"); | ||
|
||
tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); | ||
} | ||
|
||
@After | ||
public void afterTest() throws Exception { | ||
loginSysAdmin(); | ||
|
||
doDelete("/api/tenant/"+savedTenant.getId().getId().toString()) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
|
||
@Test | ||
public void testSaveDataModel() throws Exception { | ||
DataModel dataModel = new DataModel(); | ||
dataModel.setName("Drilling Data Model1"); | ||
dataModel.setLastUpdatedTs(System.currentTimeMillis()); | ||
|
||
DataModel savedDataModel = doPost("/api/data-model", dataModel, DataModel.class); | ||
|
||
Assert.assertNotNull(savedDataModel); | ||
Assert.assertNotNull(savedDataModel.getId()); | ||
Assert.assertTrue(savedDataModel.getCreatedTime() > 0); | ||
Assert.assertEquals(savedTenant.getId(), savedDataModel.getTenantId()); | ||
Assert.assertEquals(dataModel.getName(), savedDataModel.getName()); | ||
Assert.assertTrue(savedDataModel.getLastUpdatedTs() > 0); | ||
} | ||
} |
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
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
23 changes: 23 additions & 0 deletions
23
...on/src/test/java/com/hashmapinc/server/controller/nosql/DataModelControllerNoSqlTest.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,23 @@ | ||
/** | ||
* Copyright © 2017-2018 Hashmap, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hashmapinc.server.controller.nosql; | ||
|
||
import com.hashmapinc.server.controller.BaseDataModelControllerTest; | ||
import com.hashmapinc.server.dao.service.DaoNoSqlTest; | ||
|
||
@DaoNoSqlTest | ||
public class DataModelControllerNoSqlTest extends BaseDataModelControllerTest { | ||
} |
24 changes: 24 additions & 0 deletions
24
...cation/src/test/java/com/hashmapinc/server/controller/sql/DataModelControllerSqlTest.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,24 @@ | ||
/** | ||
* Copyright © 2017-2018 Hashmap, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hashmapinc.server.controller.sql; | ||
|
||
import com.hashmapinc.server.controller.BaseDataModelControllerTest; | ||
import com.hashmapinc.server.dao.service.DaoSqlTest; | ||
|
||
@DaoSqlTest | ||
public class DataModelControllerSqlTest extends BaseDataModelControllerTest { | ||
|
||
} |
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
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
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
74 changes: 74 additions & 0 deletions
74
common/data/src/main/java/com/hashmapinc/server/common/data/DataModel.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,74 @@ | ||
/** | ||
* Copyright © 2017-2018 Hashmap, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hashmapinc.server.common.data; | ||
|
||
import com.hashmapinc.server.common.data.id.DataModelId; | ||
import com.hashmapinc.server.common.data.id.TenantId; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
public class DataModel extends SearchTextBasedWithAdditionalInfo<DataModelId> implements HasName { | ||
private static final long serialVersionUID = 5100770312089703084L; | ||
|
||
private TenantId tenantId; | ||
private String name; | ||
private Long lastUpdatedTs; | ||
|
||
public DataModel() { | ||
super(); | ||
} | ||
|
||
public DataModel(DataModelId id) { | ||
super(id); | ||
} | ||
|
||
public DataModel(DataModel dataModel) { | ||
super(dataModel); | ||
this.tenantId = dataModel.getTenantId(); | ||
this.name = dataModel.getName(); | ||
this.lastUpdatedTs = dataModel.lastUpdatedTs; | ||
} | ||
|
||
public TenantId getTenantId() { | ||
return tenantId; | ||
} | ||
|
||
public void setTenantId(TenantId tenantId) { | ||
this.tenantId = tenantId; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Long getLastUpdatedTs() { | ||
return lastUpdatedTs; | ||
} | ||
|
||
public void setLastUpdatedTs(Long lastUpdatedTs) { | ||
this.lastUpdatedTs = lastUpdatedTs; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String getSearchText() { | ||
return getName(); | ||
} | ||
} |
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
Oops, something went wrong.