Skip to content

Commit

Permalink
Merge pull request #429 from hashmapinc/Tempus-310
Browse files Browse the repository at this point in the history
Tempus 310
  • Loading branch information
cherrera2001 authored Jun 8, 2018
2 parents 8feca95 + 734c794 commit ab32013
Show file tree
Hide file tree
Showing 55 changed files with 1,214 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class TempusSecurityConfiguration extends WebSecurityConfigurerAdapter {
public static final String FORM_BASED_LOGIN_ENTRY_POINT = "/api/auth/login";
public static final String PUBLIC_LOGIN_ENTRY_POINT = "/api/auth/login/public";
public static final String TOKEN_REFRESH_ENTRY_POINT = "/api/auth/token";
protected static final String[] NON_TOKEN_BASED_AUTH_ENTRY_POINTS = new String[] {"/index.html", "/static/**", "/api/noauth/**", "/api/theming/**", "/webjars/**"};
protected static final String[] NON_TOKEN_BASED_AUTH_ENTRY_POINTS = new String[] {"/index.html", "/static/**", "/api/noauth/**", "/api/theming/**", "/api/logo/**", "/webjars/**"};
public static final String TOKEN_BASED_AUTH_ENTRY_POINT = "/api/**";
public static final String WS_TOKEN_BASED_AUTH_ENTRY_POINT = "/api/ws/**";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.hashmapinc.server.common.data.Logo;
import com.hashmapinc.server.common.data.Theme;
import com.hashmapinc.server.common.data.User;
import com.hashmapinc.server.common.data.UserSettings;
Expand All @@ -25,18 +26,24 @@
import com.hashmapinc.server.common.data.id.UserId;
import com.hashmapinc.server.common.data.page.TextPageLink;
import com.hashmapinc.server.common.data.security.Authority;
import com.hashmapinc.server.dao.logo.LogoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.hashmapinc.server.dao.settings.UserSettingsService;
import com.hashmapinc.server.dao.theme.ThemeService;
import com.hashmapinc.server.exception.TempusException;
import com.hashmapinc.server.service.mail.MailService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;


@Slf4j
@RestController
Expand All @@ -52,6 +59,9 @@ public class UserSettingsController extends BaseController {
@Autowired
private ThemeService themeService;

@Autowired
private LogoService logoService;

@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER', 'SYS_ADMIN')")
@RequestMapping(value = "/settings/{key}", method = RequestMethod.GET)
@ResponseBody
Expand Down Expand Up @@ -128,4 +138,42 @@ public Theme updateTheme(@RequestBody String value) throws TempusException {
}
}

@PreAuthorize("hasAuthority('SYS_ADMIN')")
@RequestMapping(value = "/settings/uploadLogo", method = RequestMethod.POST)
public Logo uploadLogo(@RequestParam("file") MultipartFile file) throws TempusException {
try {

Logo l = new Logo();
l.setDisplay(true);
l.setName(file.getOriginalFilename());
l.setFile(file.getBytes());

return logoService.saveLogo(l);
// return null;
} catch (Exception e) {
throw handleException(e);
}
}

@RequestMapping(value = "/logo", method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)
public Logo getLogo() throws TempusException {
try {

List <Logo> logo = logoService.find();

if(logo.size() > 0) {

return logo.get(0);
}

return null;

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



}
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ public void performInstall() {

componentDiscoveryService.discoverComponents();

systemDataLoaderService.loadSystemThemes();
systemDataLoaderService.createSysAdmin();
systemDataLoaderService.createAdminSettings();
systemDataLoaderService.loadSystemWidgets();
systemDataLoaderService.loadSystemPlugins();
systemDataLoaderService.loadSystemRules();
systemDataLoaderService.loadSystemThemes();


if (loadDemo) {
log.info("Loading demo data...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void createDatabaseSchema() throws Exception {

for (Integer i : sortedScriptsIndexes) {
String scriptFileName = i.toString() + ".cql";
log.info("Installing pending upgrades ..." + scriptFileName);
if (!executedUpgrades.contains(scriptFileName)) {
loadCql(upgradeScriptsDirectory.resolve(scriptFileName));
cluster.getSession().execute("insert into " + tempus_KEYSPACE + "." + ModelConstants.INSTALLED_SCHEMA_VERSIONS + "(" + ModelConstants.INSTALLED_SCRIPTS_COLUMN + ")" + " values('" + scriptFileName + "'" + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,24 @@ public void createAdminSettings() throws Exception {

public void loadSystemThemes() throws Exception {

log.info("Loading theme data...");
Theme theme1 = new Theme();
theme1.setThemeName("Tempus Blue");
theme1.setThemeValue("themeBlue");
theme1.setThemeStatus(false);
themeService.saveTheme(theme1);

Theme theme2 = new Theme();
theme2.setThemeName("Tempus Dark");
theme2.setThemeValue("themeDark");
theme2.setThemeStatus(true);
themeService.saveTheme(theme2);
List<Theme> theme = themeService.findAll();

if(theme.size() < 2) {

log.info("Loading theme data...");
Theme theme1 = new Theme();
theme1.setThemeName("Tempus Blue");
theme1.setThemeValue("themeBlue");
theme1.setThemeStatus(false);
themeService.saveTheme(theme1);

Theme theme2 = new Theme();
theme2.setThemeName("Tempus Dark");
theme2.setThemeValue("themeDark");
theme2.setThemeStatus(true);
themeService.saveTheme(theme2);

}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.hashmapinc.server.common.data.Logo;
import com.hashmapinc.server.common.data.User;
import com.hashmapinc.server.common.data.Theme;
import com.hashmapinc.server.common.data.id.ThemeId;
import com.hashmapinc.server.common.data.UserSettings;
import com.hashmapinc.server.dao.logo.LogoService;
import org.junit.Assert;
import com.hashmapinc.server.dao.theme.ThemeService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -41,6 +43,9 @@ public abstract class BaseUserSettingsControllerTest extends AbstractControllerT
@Autowired
ThemeService themeService;

@Autowired
LogoService logoService;

private static final ObjectMapper mapper = new ObjectMapper();

@Test
Expand Down Expand Up @@ -208,5 +213,25 @@ public void getThemes() throws Exception{

}


@Test
public void getLogo() throws Exception{

byte[] aByteArray = {0xa,0x2,0xf,(byte)0xff,(byte)0xff,(byte)0xff};

Logo logo = new Logo();
logo.setName("test.jpg");
logo.setDisplay(true);
logo.setFile(aByteArray);
logoService.saveLogo(logo);

Logo logoNew = doGet("/api/logo", Logo.class);

Assert.assertEquals(logo.isDisplay(),logoNew.isDisplay());

logoService.deleteLogoByName(logoNew.getName());

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public class ControllerSqlTestSuite {
Arrays.asList("sql/schema.sql", "sql/system-data.sql"),
"sql/drop-all-tables.sql",
"sql-test.properties",
Arrays.asList("sql/upgrade/1.sql", "sql/upgrade/2.sql")
Arrays.asList("sql/upgrade/1.sql", "sql/upgrade/2.sql", "sql/upgrade/3.sql")
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public class MqttSqlTestSuite {
Arrays.asList("sql/schema.sql", "sql/system-data.sql"),
"sql/drop-all-tables.sql",
"sql-test.properties",
Arrays.asList("sql/upgrade/1.sql", "sql/upgrade/2.sql"));
Arrays.asList("sql/upgrade/1.sql", "sql/upgrade/2.sql", "sql/upgrade/3.sql"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SystemSqlTestSuite {
Arrays.asList("sql/schema.sql", "sql/system-data.sql"),
"sql/drop-all-tables.sql",
"sql-test.properties",
Arrays.asList("sql/upgrade/1.sql", "sql/upgrade/2.sql")
Arrays.asList("sql/upgrade/1.sql", "sql/upgrade/2.sql", "sql/upgrade/3.sql")
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

public enum EntityType {

TENANT, CUSTOMER, USER, RULE, PLUGIN, DASHBOARD, ASSET, DEVICE, ALARM, APPLICATION, COMPUTATION, COMPUTATION_JOB, NODE_METRIC,THEME
TENANT, CUSTOMER, USER, RULE, PLUGIN, DASHBOARD, ASSET, DEVICE, ALARM, APPLICATION, COMPUTATION, COMPUTATION_JOB, NODE_METRIC,THEME,LOGO

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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.BaseData;
import com.hashmapinc.server.common.data.id.LogoId;
import lombok.EqualsAndHashCode;


public class Logo extends BaseData<LogoId> {

private boolean display;
private byte[] file;
private String name;

public Logo() {
super();
}


public Logo(LogoId id) {
super(id);
}

public Logo(Logo logo) {
super(logo);
this.file = logo.file;
this.display = logo.display;
this.name = logo.name;
}


public boolean isDisplay() {
return display;
}

public void setDisplay(boolean display) {
this.display = display;
}

public byte[] getFile() {
return file;
}

public void setFile(byte[] file) {
this.file = file;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}


@Override
public String toString() {
return "logo{" +
"display=" + display +
", file=" + file +
",logoName=" + name +
'}';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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.id;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.hashmapinc.server.common.data.EntityType;

import java.util.UUID;


public final class LogoId extends UUIDBased implements EntityId {

private static final long serialVersionUID = 1L;

@JsonCreator
public LogoId(@JsonProperty("id") UUID id) {
super(id);
}

public static LogoId fromString(String logoId) {
return new LogoId(UUID.fromString(logoId));
}

@JsonIgnore
@Override
public EntityType getEntityType() {
return EntityType.LOGO;
}

}
Loading

0 comments on commit ab32013

Please sign in to comment.