From a7b9c784bb62921391a3ea4b4e300a9ae6c4d580 Mon Sep 17 00:00:00 2001 From: Shobhit2884 Date: Tue, 5 Jun 2018 13:32:46 +0530 Subject: [PATCH 1/6] Commit code for Logo functionality --- .../controller/UserSettingsController.java | 29 ++++++ .../CassandraDatabaseSchemaService.java | 1 + .../hashmapinc/server/common/data/Logo.java | 80 ++++++++++++++++ .../server/common/data/id/LogoId.java | 45 +++++++++ .../hashmapinc/server/dao/logo/LogoDao.java | 38 ++++++++ .../server/dao/logo/LogoService.java | 33 +++++++ .../server/dao/logo/LogoServiceImpl.java | 63 +++++++++++++ .../server/dao/model/ModelConstants.java | 11 +++ .../server/dao/model/sql/LogoEntity.java | 73 +++++++++++++++ .../server/dao/sql/logo/JpaLogoDao.java | 64 +++++++++++++ .../server/dao/sql/logo/LogoRepository.java | 28 ++++++ dao/src/main/resources/cassandra/schema.cql | 2 + .../main/resources/cassandra/upgrade/2.cql | 25 +++++ dao/src/main/resources/sql/upgrade/4.sql | 22 +++++ ui/src/app/admin/admin.controller.js | 10 +- ui/src/app/admin/theme-settings.tpl.html | 6 +- .../import-export/import-dialog.controller.js | 15 ++- .../app/import-export/import-dialog.tpl.html | 2 +- .../import-export/import-export.service.js | 93 ++++++++++++++----- ui/src/app/locale/locale.constant.js | 4 +- 20 files changed, 606 insertions(+), 38 deletions(-) create mode 100644 common/data/src/main/java/com/hashmapinc/server/common/data/Logo.java create mode 100644 common/data/src/main/java/com/hashmapinc/server/common/data/id/LogoId.java create mode 100644 dao/src/main/java/com/hashmapinc/server/dao/logo/LogoDao.java create mode 100644 dao/src/main/java/com/hashmapinc/server/dao/logo/LogoService.java create mode 100644 dao/src/main/java/com/hashmapinc/server/dao/logo/LogoServiceImpl.java create mode 100644 dao/src/main/java/com/hashmapinc/server/dao/model/sql/LogoEntity.java create mode 100644 dao/src/main/java/com/hashmapinc/server/dao/sql/logo/JpaLogoDao.java create mode 100644 dao/src/main/java/com/hashmapinc/server/dao/sql/logo/LogoRepository.java create mode 100644 dao/src/main/resources/cassandra/upgrade/2.cql create mode 100644 dao/src/main/resources/sql/upgrade/4.sql diff --git a/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java b/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java index bff19cfc2..4c4a05847 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java @@ -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; @@ -25,11 +26,13 @@ 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; @@ -37,6 +40,10 @@ import javax.servlet.http.HttpServletRequest; import java.util.List; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + @Slf4j @RestController @@ -52,6 +59,8 @@ public class UserSettingsController extends BaseController { @Autowired private ThemeService themeService; + private LogoService logoService; + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER', 'SYS_ADMIN')") @RequestMapping(value = "/settings/{key}", method = RequestMethod.GET) @ResponseBody @@ -128,4 +137,24 @@ 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.getName()); + l.setFile(file.getBytes()); + //JsonObject request = new JsonParser().parse(value).getAsJsonObject(); + //return themeService.updateThemeStatus(request.get("value").getAsString()); + + return logoService.saveLogo(l); + // return null; + } catch (Exception e) { + throw handleException(e); + } + } + + } diff --git a/application/src/main/java/com/hashmapinc/server/service/install/CassandraDatabaseSchemaService.java b/application/src/main/java/com/hashmapinc/server/service/install/CassandraDatabaseSchemaService.java index 6d3655385..1c6de1a6b 100644 --- a/application/src/main/java/com/hashmapinc/server/service/install/CassandraDatabaseSchemaService.java +++ b/application/src/main/java/com/hashmapinc/server/service/install/CassandraDatabaseSchemaService.java @@ -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 + "'" + ")"); diff --git a/common/data/src/main/java/com/hashmapinc/server/common/data/Logo.java b/common/data/src/main/java/com/hashmapinc/server/common/data/Logo.java new file mode 100644 index 000000000..62ca66b70 --- /dev/null +++ b/common/data/src/main/java/com/hashmapinc/server/common/data/Logo.java @@ -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 { + + 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 + + '}'; + } + +} diff --git a/common/data/src/main/java/com/hashmapinc/server/common/data/id/LogoId.java b/common/data/src/main/java/com/hashmapinc/server/common/data/id/LogoId.java new file mode 100644 index 000000000..d0e2ac576 --- /dev/null +++ b/common/data/src/main/java/com/hashmapinc/server/common/data/id/LogoId.java @@ -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; + } + +} diff --git a/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoDao.java b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoDao.java new file mode 100644 index 000000000..fce88f4c6 --- /dev/null +++ b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoDao.java @@ -0,0 +1,38 @@ +/** + * 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.dao.logo; +import com.hashmapinc.server.common.data.Logo; +import com.hashmapinc.server.dao.Dao; + +import java.util.List; + + +public interface LogoDao extends Dao { + + /** + * Find theme for listing + * @return the list of logo objects + */ + List find(); + + Logo save(Logo logo); + + Logo findById(String id); + + +} diff --git a/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoService.java b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoService.java new file mode 100644 index 000000000..2fd545bab --- /dev/null +++ b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoService.java @@ -0,0 +1,33 @@ +/** + * 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.dao.logo; +import com.hashmapinc.server.common.data.Logo; + +import java.util.List; + +public interface LogoService { + + Logo find(); + + Logo saveLogo(Logo logo); + + void deleteLogoById(String id); + + +} diff --git a/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoServiceImpl.java b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoServiceImpl.java new file mode 100644 index 000000000..b5ae19aab --- /dev/null +++ b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoServiceImpl.java @@ -0,0 +1,63 @@ +/** + * 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.dao.logo; + +import com.hashmapinc.server.dao.logo.LogoDao; +import com.hashmapinc.server.common.data.Logo; +import com.hashmapinc.server.dao.entity.AbstractEntityService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +@Slf4j +public class LogoServiceImpl extends AbstractEntityService implements LogoService { + + @Autowired + private LogoDao logoDao; + + @Override + public Logo find() { + return logoDao.find().get(0); + } + + @Override + public Logo saveLogo(Logo logo) { + Logo logoNew = logoDao.save(logo); + if(logoNew != null) { + return logoNew; + } + return null; + } + + + @Override + public void deleteLogoById (String id) { + + Logo logo = logoDao.findById(id); + + if (logo != null) { + + logoDao.removeById(logo.getUuidId()); + } + } +} diff --git a/dao/src/main/java/com/hashmapinc/server/dao/model/ModelConstants.java b/dao/src/main/java/com/hashmapinc/server/dao/model/ModelConstants.java index 6e680e7e9..8939fe1a5 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/model/ModelConstants.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/model/ModelConstants.java @@ -482,6 +482,17 @@ private ModelConstants() { public static final String THEME_VALUE_PROPERTY = "value"; public static final String THEME_IS_ENABLED_PROPERTY = "is_enabled"; + + /** + * logo constants. + */ + public static final String LOGO_TABLE_NAME = "logo"; + public static final String LOGO_NAME = "name"; + public static final String LOGO_DISPLAY = "enabled"; + public static final String LOGO_FILE = "file"; + + + /** * Main names of cassandra key-value columns storage. */ diff --git a/dao/src/main/java/com/hashmapinc/server/dao/model/sql/LogoEntity.java b/dao/src/main/java/com/hashmapinc/server/dao/model/sql/LogoEntity.java new file mode 100644 index 000000000..cfd310b59 --- /dev/null +++ b/dao/src/main/java/com/hashmapinc/server/dao/model/sql/LogoEntity.java @@ -0,0 +1,73 @@ +/** + * 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.dao.model.sql; + +import com.hashmapinc.server.common.data.Logo; +import com.hashmapinc.server.common.data.id.LogoId; +import com.hashmapinc.server.dao.model.BaseEntity; +import com.hashmapinc.server.dao.model.BaseSqlEntity; +import com.hashmapinc.server.dao.model.ModelConstants; +import com.hashmapinc.server.dao.util.mapping.JsonStringType; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.TypeDef; + +import javax.persistence.*; + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Table(name = ModelConstants.LOGO_TABLE_NAME) + +public class LogoEntity extends BaseSqlEntityimplements BaseEntity { + + @Column(name = ModelConstants.LOGO_NAME) + private String name; + + @Column(name = ModelConstants.LOGO_DISPLAY) + private boolean display; + + + @Column(name = ModelConstants.LOGO_FILE) + private byte[] file; + + + public LogoEntity() { + super(); + } + + public LogoEntity(Logo logo) { + if (logo.getId() != null) { + this.setId(logo.getId().getId()); + } + + this.name = logo.getName(); + this.display = logo.isDisplay(); + this.file = logo.getFile(); + } + + @Override + public Logo toData() { + Logo logo = new Logo(new LogoId(getId())); + logo.setName(name); + logo.setDisplay(display); + logo.setFile(file); + return logo; + } + +} diff --git a/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/JpaLogoDao.java b/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/JpaLogoDao.java new file mode 100644 index 000000000..b3f55aa54 --- /dev/null +++ b/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/JpaLogoDao.java @@ -0,0 +1,64 @@ +/** + * 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.dao.sql.logo; + +import com.hashmapinc.server.common.data.Logo; +import com.hashmapinc.server.dao.DaoUtil; +import com.hashmapinc.server.dao.model.sql.LogoEntity; +import com.hashmapinc.server.dao.sql.JpaAbstractDao; +import com.hashmapinc.server.dao.logo.LogoDao; +import com.hashmapinc.server.dao.util.SqlDao; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +@Component +@SqlDao +@Slf4j + + +public class JpaLogoDao extends JpaAbstractDao implements LogoDao { + + @Autowired + private LogoRepository logoRepository; + + @Override + protected Class getEntityClass() { + return LogoEntity.class; + } + + @Override + protected CrudRepository getCrudRepository() { + return logoRepository; + } + + @Override + public Logo findById(String id) { + Logo logo = DaoUtil.getData(logoRepository.findById(id)); + if (logo != null) { + return logo; + } else { + return null; + } + } + + +} diff --git a/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/LogoRepository.java b/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/LogoRepository.java new file mode 100644 index 000000000..4ea5e78b7 --- /dev/null +++ b/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/LogoRepository.java @@ -0,0 +1,28 @@ +/** + * 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.dao.sql.logo; +import com.hashmapinc.server.dao.model.sql.LogoEntity; +import com.hashmapinc.server.dao.util.SqlDao; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; + +@SqlDao +public interface LogoRepository extends CrudRepository { + + LogoEntity findById(String id); +} diff --git a/dao/src/main/resources/cassandra/schema.cql b/dao/src/main/resources/cassandra/schema.cql index 5a1ec8aad..f749cc52f 100644 --- a/dao/src/main/resources/cassandra/schema.cql +++ b/dao/src/main/resources/cassandra/schema.cql @@ -781,6 +781,7 @@ CREATE TABLE IF NOT EXISTS tempus.audit_log_by_tenant_id_partitions ( ) WITH CLUSTERING ORDER BY ( partition ASC ) AND compaction = { 'class' : 'LeveledCompactionStrategy' }; + CREATE TABLE IF NOT EXISTS tempus.theme ( id uuid, name text, @@ -788,3 +789,4 @@ CREATE TABLE IF NOT EXISTS tempus.theme ( is_enabled boolean, PRIMARY KEY (id,name) ); + diff --git a/dao/src/main/resources/cassandra/upgrade/2.cql b/dao/src/main/resources/cassandra/upgrade/2.cql new file mode 100644 index 000000000..68652a131 --- /dev/null +++ b/dao/src/main/resources/cassandra/upgrade/2.cql @@ -0,0 +1,25 @@ +-- +-- 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. +-- + +CREATE TABLE IF NOT EXISTS tempus.theme ( + id uuid, + name text, + value text, + is_enabled boolean, + PRIMARY KEY (id,name) +); + + diff --git a/dao/src/main/resources/sql/upgrade/4.sql b/dao/src/main/resources/sql/upgrade/4.sql new file mode 100644 index 000000000..319176782 --- /dev/null +++ b/dao/src/main/resources/sql/upgrade/4.sql @@ -0,0 +1,22 @@ +-- +-- 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. +-- + +CREATE TABLE IF NOT EXISTS logo ( + id varchar (31) NOT NULL CONSTRAINT logo_pkey PRIMARY KEY, + name varchar, + enabled boolean, + file bytea + ); diff --git a/ui/src/app/admin/admin.controller.js b/ui/src/app/admin/admin.controller.js index b125dfcd2..e58903ec3 100644 --- a/ui/src/app/admin/admin.controller.js +++ b/ui/src/app/admin/admin.controller.js @@ -17,7 +17,7 @@ import changeThemeTemplate from './change-theme.tpl.html'; /*@ngInject*/ -export default function AdminController(adminService, toast, $scope, $rootScope, $state, $translate, $mdDialog, $document) { +export default function AdminController(adminService, toast, $scope, $rootScope, $state, $translate, $mdDialog, $document,importExport) { var vm = this; vm.save = save; @@ -110,12 +110,10 @@ export default function AdminController(adminService, toast, $scope, $rootScope, } - function changeLogo() { + function changeLogo($event) { - // importExport.importComputation($event) + importExport.importLogo($event) } - - -} +} \ No newline at end of file diff --git a/ui/src/app/admin/theme-settings.tpl.html b/ui/src/app/admin/theme-settings.tpl.html index d7521f587..2730d21d1 100644 --- a/ui/src/app/admin/theme-settings.tpl.html +++ b/ui/src/app/admin/theme-settings.tpl.html @@ -27,9 +27,9 @@ class="md-raised md-primary">{{ 'admin.change-theme' | translate }} - - - + {{ 'admin.change-logo' | translate }} + diff --git a/ui/src/app/import-export/import-dialog.controller.js b/ui/src/app/import-export/import-dialog.controller.js index cbf12fee0..92ff507fd 100644 --- a/ui/src/app/import-export/import-dialog.controller.js +++ b/ui/src/app/import-export/import-dialog.controller.js @@ -33,7 +33,7 @@ export default function ImportDialogController($scope, $log, $mdDialog, toast, i $mdDialog.cancel(); } - function fileAdded($file) { + function fileAdded($file) {$log.log($file.getType()); if ($file.getExtension() === 'json') { var reader = new FileReader(); reader.onload = function(event) { @@ -59,9 +59,16 @@ export default function ImportDialogController($scope, $log, $mdDialog, toast, i else if ($file.getExtension() === 'jar') { $scope.$apply(function() { $scope.theForm.$setDirty(); - vm.importData = $file; - vm.fileName = $file.name; + vm.importData = $file; + vm.fileName = $file.name; }) + } else if($file.getExtension() === 'png' || $file.getExtension() === 'jpeg' || $file.getExtension() === 'svg' || $file.getExtension() === 'jpg') { + $scope.$apply(function() { + $scope.theForm.$setDirty(); + vm.importData = $file; + vm.fileName = $file.name; + }) + } } @@ -76,4 +83,4 @@ export default function ImportDialogController($scope, $log, $mdDialog, toast, i $scope.theForm.$setPristine(); $mdDialog.hide(vm.importData); } -} +} \ No newline at end of file diff --git a/ui/src/app/import-export/import-dialog.tpl.html b/ui/src/app/import-export/import-dialog.tpl.html index afc8a8480..1339e5742 100644 --- a/ui/src/app/import-export/import-dialog.tpl.html +++ b/ui/src/app/import-export/import-dialog.tpl.html @@ -49,7 +49,7 @@

{{ vm.importTitle }}

- +
diff --git a/ui/src/app/import-export/import-export.service.js b/ui/src/app/import-export/import-export.service.js index 9a57e3cb7..0a98f67e1 100644 --- a/ui/src/app/import-export/import-export.service.js +++ b/ui/src/app/import-export/import-export.service.js @@ -18,6 +18,7 @@ import importDialogTemplate from './import-dialog.tpl.html'; import entityAliasesTemplate from '../entity/alias/entity-aliases.tpl.html'; + /* eslint-enable import/no-unresolved, import/default */ @@ -45,7 +46,8 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, importComputation: importComputation, exportExtension: exportExtension, importExtension: importExtension, - exportToPc: exportToPc + exportToPc: exportToPc, + importLogo: importLogo, }; return service; @@ -61,8 +63,8 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, function success (widgetTypes) { prepareExport(widgetsBundle); var widgetsBundleItem = { - widgetsBundle: prepareExport(widgetsBundle), - widgetTypes: [] + widgetsBundle: prepareExport(widgetsBundle), + widgetTypes: [] }; for (var t in widgetTypes) { var widgetType = widgetTypes[t]; @@ -328,15 +330,15 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, var deferred = $q.defer(); openImportDialog($event, 'computation.import', 'computation.computation-file').then( function success(importData) { - computationService.upload(importData.file).then( - function success() { - deferred.resolve(); - $window.localStorage.setItem('currentTab', 4); - }, - function fail() { - deferred.reject(); - } - ); + computationService.upload(importData.file).then( + function success() { + deferred.resolve(); + $window.localStorage.setItem('currentTab', 4); + }, + function fail() { + deferred.reject(); + } + ); }, function fail() { deferred.reject(); @@ -345,6 +347,28 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, return deferred.promise; } + function importLogo($event) { + var deferred = $q.defer(); + openImportDialog($event, 'admin.import', 'admin.logo-file').then( + function success(importData) { $log.log(importData); + // computationService.upload(importData.file).then( + // function success() { + // deferred.resolve(); + // + // }, + // function fail() { + // deferred.reject(); + // } + // ); + }, + function fail() { + deferred.reject(); + } + ); + return deferred.promise; + } + + function validateImportedPlugin(plugin) { if (angular.isUndefined(plugin.name) || angular.isUndefined(plugin.clazz) @@ -474,7 +498,7 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, function(missingEntityAliases) { if (Object.keys(missingEntityAliases).length > 0) { editMissingAliases($event, [ widget ], - true, 'dashboard.widget-import-missing-aliases-title', missingEntityAliases).then( + true, 'dashboard.widget-import-missing-aliases-title', missingEntityAliases).then( function success(updatedEntityAliases) { for (var aliasId in updatedEntityAliases) { var entityAlias = updatedEntityAliases[aliasId]; @@ -539,14 +563,14 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, function success(targetLayout) { itembuffer.addWidgetToDashboard(dashboard, targetState, targetLayout, widget, aliasesInfo, onAliasesUpdateFunction, originalColumns, originalSize, -1, -1).then( - function() { - deferred.resolve( - { - widget: widget, - layoutId: targetLayout - } - ); - } + function() { + deferred.resolve( + { + widget: widget, + layoutId: targetLayout + } + ); + } ); }, function fail() { @@ -600,7 +624,7 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, function(missingEntityAliases) { if (Object.keys( missingEntityAliases ).length > 0) { editMissingAliases($event, dashboard.configuration.widgets, - false, 'dashboard.dashboard-import-missing-aliases-title', missingEntityAliases).then( + false, 'dashboard.dashboard-import-missing-aliases-title', missingEntityAliases).then( function success(updatedEntityAliases) { for (var aliasId in updatedEntityAliases) { entityAliases[aliasId] = updatedEntityAliases[aliasId]; @@ -863,6 +887,29 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, return deferred.promise; } + // function openImportDialogLogo($event, importTitle, importFileLabel) { $log.log(importLogoDialogTemplate); + // var deferred = $q.defer(); + // $mdDialog.show({ + // controller: 'ImportDialogController', + // controllerAs: 'vm', + // templateUrl: importDialogTemplate, + // locals: { + // importTitle: importTitle, + // importFileLabel: importFileLabel + // }, + // parent: angular.element($document[0].body), + // skipHide: true, + // fullscreen: true, + // targetEvent: $event + // }).then(function (importData) { + // deferred.resolve(importData); + // }, function () { + // deferred.reject(); + // }); + // return deferred.promise; + // } + + } -/* eslint-enable no-undef, angular/window-service, angular/document-service */ +/* eslint-enable no-undef, angular/window-service, angular/document-service */ \ No newline at end of file diff --git a/ui/src/app/locale/locale.constant.js b/ui/src/app/locale/locale.constant.js index cf9719ce0..25df9651f 100644 --- a/ui/src/app/locale/locale.constant.js +++ b/ui/src/app/locale/locale.constant.js @@ -110,7 +110,9 @@ export default angular.module('tempus.locale', []) "change-logo":"Change Logo", "current-theme":"Current theme", "select-theme":"Select theme", - "bad-request": "Bad Request,Please Select A Theme." + "bad-request": "Bad Request,Please Select A Theme.", + "logo-file":"Logo file", + "import":"Upload Logo" }, "alarm": { From c0a2dd18f0a56b4fd7131267f931a4de58079c7e Mon Sep 17 00:00:00 2001 From: Shobhit2884 Date: Thu, 7 Jun 2018 11:24:16 +0530 Subject: [PATCH 2/6] Commit code for logo functionality --- .../config/TempusSecurityConfiguration.java | 2 +- .../controller/UserSettingsController.java | 25 +++- .../BaseUserSettingsControllerTest.java | 25 ++++ .../server/common/data/EntityType.java | 2 +- .../server/dao/logo/CassandraLogoDao.java | 69 ++++++++++ .../hashmapinc/server/dao/logo/LogoDao.java | 2 + .../server/dao/logo/LogoService.java | 4 +- .../server/dao/logo/LogoServiceImpl.java | 14 +- .../server/dao/model/ModelConstants.java | 10 ++ .../server/dao/model/nosql/LogoEntity.java | 124 ++++++++++++++++++ .../server/dao/sql/logo/JpaLogoDao.java | 12 ++ .../server/dao/sql/logo/LogoRepository.java | 2 + .../server/dao/theme/CassandraThemeDao.java | 2 + .../hashmapinc/server/dao/theme/ThemeDao.java | 2 + .../main/resources/cassandra/upgrade/3.cql | 24 ++++ dao/src/main/resources/sql/upgrade/5.sql | 23 ++++ .../server/dao/JpaDaoTestSuite.java | 2 +- .../server/dao/NoSqlDaoServiceTestSuite.java | 5 + .../server/dao/SqlDaoServiceTestSuite.java | 2 +- .../dao/service/AbstractServiceTest.java | 6 + .../dao/service/BaseLogoServiceTest.java | 53 ++++++++ .../service/nosql/LogoServiceNoSqlTest.java | 25 ++++ .../dao/service/sql/LogoServiceSqlTest.java | 27 ++++ .../test/resources/sql/drop-all-tables.sql | 1 + ui/src/app/admin/admin.controller.js | 19 ++- ui/src/app/api/admin.service.js | 19 ++- ui/src/app/api/user.service.js | 17 ++- ui/src/app/app.run.js | 22 +++- .../import-export/import-export.service.js | 24 ++-- ui/src/app/layout/home.tpl.html | 10 +- ui/src/app/locale/locale.constant.js | 3 +- ui/src/app/login/login.controller.js | 2 + ui/src/app/login/login.tpl.html | 7 +- 33 files changed, 553 insertions(+), 33 deletions(-) create mode 100644 dao/src/main/java/com/hashmapinc/server/dao/logo/CassandraLogoDao.java create mode 100644 dao/src/main/java/com/hashmapinc/server/dao/model/nosql/LogoEntity.java create mode 100644 dao/src/main/resources/cassandra/upgrade/3.cql create mode 100644 dao/src/main/resources/sql/upgrade/5.sql create mode 100644 dao/src/test/java/com/hashmapinc/server/dao/service/BaseLogoServiceTest.java create mode 100644 dao/src/test/java/com/hashmapinc/server/dao/service/nosql/LogoServiceNoSqlTest.java create mode 100644 dao/src/test/java/com/hashmapinc/server/dao/service/sql/LogoServiceSqlTest.java diff --git a/application/src/main/java/com/hashmapinc/server/config/TempusSecurityConfiguration.java b/application/src/main/java/com/hashmapinc/server/config/TempusSecurityConfiguration.java index 523f82637..a23d38cd4 100644 --- a/application/src/main/java/com/hashmapinc/server/config/TempusSecurityConfiguration.java +++ b/application/src/main/java/com/hashmapinc/server/config/TempusSecurityConfiguration.java @@ -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/**"; diff --git a/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java b/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java index 4c4a05847..1c42760b2 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java @@ -59,6 +59,7 @@ public class UserSettingsController extends BaseController { @Autowired private ThemeService themeService; + @Autowired private LogoService logoService; @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER', 'SYS_ADMIN')") @@ -144,10 +145,8 @@ public Logo uploadLogo(@RequestParam("file") MultipartFile file) throws TempusEx Logo l = new Logo(); l.setDisplay(true); - l.setName(file.getName()); + l.setName(file.getOriginalFilename()); l.setFile(file.getBytes()); - //JsonObject request = new JsonParser().parse(value).getAsJsonObject(); - //return themeService.updateThemeStatus(request.get("value").getAsString()); return logoService.saveLogo(l); // return null; @@ -156,5 +155,25 @@ public Logo uploadLogo(@RequestParam("file") MultipartFile file) throws TempusEx } } + @RequestMapping(value = "/logo", method = RequestMethod.GET) + @ResponseStatus(value = HttpStatus.OK) + public Logo getLogo() throws TempusException { + try { + + List logo = logoService.find(); + + if(logo.size() > 0) { + + return logo.get(0); + } + + return null; + + } catch (Exception e) { + throw handleException(e); + } + } + + } diff --git a/application/src/test/java/com/hashmapinc/server/controller/BaseUserSettingsControllerTest.java b/application/src/test/java/com/hashmapinc/server/controller/BaseUserSettingsControllerTest.java index f27ca61ed..b6115f176 100644 --- a/application/src/test/java/com/hashmapinc/server/controller/BaseUserSettingsControllerTest.java +++ b/application/src/test/java/com/hashmapinc/server/controller/BaseUserSettingsControllerTest.java @@ -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; @@ -41,6 +43,9 @@ public abstract class BaseUserSettingsControllerTest extends AbstractControllerT @Autowired ThemeService themeService; + @Autowired + LogoService logoService; + private static final ObjectMapper mapper = new ObjectMapper(); @Test @@ -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()); + + } + } diff --git a/common/data/src/main/java/com/hashmapinc/server/common/data/EntityType.java b/common/data/src/main/java/com/hashmapinc/server/common/data/EntityType.java index efae63c99..f4f2c0782 100644 --- a/common/data/src/main/java/com/hashmapinc/server/common/data/EntityType.java +++ b/common/data/src/main/java/com/hashmapinc/server/common/data/EntityType.java @@ -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 } diff --git a/dao/src/main/java/com/hashmapinc/server/dao/logo/CassandraLogoDao.java b/dao/src/main/java/com/hashmapinc/server/dao/logo/CassandraLogoDao.java new file mode 100644 index 000000000..a2cf1405a --- /dev/null +++ b/dao/src/main/java/com/hashmapinc/server/dao/logo/CassandraLogoDao.java @@ -0,0 +1,69 @@ +/** + * 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.dao.logo; + +import com.hashmapinc.server.common.data.Logo; +import com.hashmapinc.server.dao.DaoUtil; +import com.hashmapinc.server.dao.model.ModelConstants; +import com.hashmapinc.server.dao.model.nosql.LogoEntity; +import com.hashmapinc.server.dao.nosql.CassandraAbstractModelDao; +import com.hashmapinc.server.dao.util.NoSqlDao; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import com.datastax.driver.core.querybuilder.Select; + +import java.util.Optional; +import com.datastax.driver.core.querybuilder.Select.Where; +import static com.datastax.driver.core.querybuilder.QueryBuilder.select; +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; + +@Component +@Slf4j +@NoSqlDao + + +public class CassandraLogoDao extends CassandraAbstractModelDao implements LogoDao{ + + @Override + protected Class getColumnFamilyClass() { + return LogoEntity.class; + } + + @Override + protected String getColumnFamilyName() { + return ModelConstants.LOGO_COLUMN_FAMILY_NAME; + } + + @Override + public Logo findById(String id) { + Select select = select().from(ModelConstants.LOGO_COLUMN_FAMILY_NAME).allowFiltering(); + Select.Where query = select.where(); + query.and(eq(ModelConstants.ID_PROPERTY,id)); + return DaoUtil.getData(findOneByStatement(query)); + } + + @Override + public Logo findByName(String name) { + Select select = select().from(ModelConstants.LOGO_COLUMN_FAMILY_NAME).allowFiltering(); + Select.Where query = select.where(); + query.and(eq(ModelConstants.LOGO_NAME_PROPERTY,name)); + return DaoUtil.getData(findOneByStatement(query)); + } + + +} diff --git a/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoDao.java b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoDao.java index fce88f4c6..813504e95 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoDao.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoDao.java @@ -34,5 +34,7 @@ public interface LogoDao extends Dao { Logo findById(String id); + Logo findByName(String name); + } diff --git a/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoService.java b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoService.java index 2fd545bab..48d0e01e4 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoService.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoService.java @@ -23,11 +23,11 @@ public interface LogoService { - Logo find(); + List find(); Logo saveLogo(Logo logo); - void deleteLogoById(String id); + void deleteLogoByName(String name); } diff --git a/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoServiceImpl.java b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoServiceImpl.java index b5ae19aab..3ea585226 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoServiceImpl.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/logo/LogoServiceImpl.java @@ -36,12 +36,18 @@ public class LogoServiceImpl extends AbstractEntityService implements LogoServic private LogoDao logoDao; @Override - public Logo find() { - return logoDao.find().get(0); + public List find() { + return logoDao.find(); } @Override public Logo saveLogo(Logo logo) { + List logoOld = find(); + + if(logoOld.size() > 0) { + + logoDao.removeById(logoOld.get(0).getUuidId()); + } Logo logoNew = logoDao.save(logo); if(logoNew != null) { return logoNew; @@ -51,9 +57,9 @@ public Logo saveLogo(Logo logo) { @Override - public void deleteLogoById (String id) { + public void deleteLogoByName (String name) { - Logo logo = logoDao.findById(id); + Logo logo = logoDao.findByName(name); if (logo != null) { diff --git a/dao/src/main/java/com/hashmapinc/server/dao/model/ModelConstants.java b/dao/src/main/java/com/hashmapinc/server/dao/model/ModelConstants.java index 8939fe1a5..c77a4f792 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/model/ModelConstants.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/model/ModelConstants.java @@ -483,6 +483,16 @@ private ModelConstants() { public static final String THEME_IS_ENABLED_PROPERTY = "is_enabled"; + + /** + * Cassandra logo Constants + */ + public static final String LOGO_COLUMN_FAMILY_NAME = "logo"; + public static final String LOGO_NAME_PROPERTY = "name"; + public static final String LOGO_DISPLAY_PROPERTY = "enabled"; + public static final String LOGO_FILE_PROPERTY = "file"; + + /** * logo constants. */ diff --git a/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/LogoEntity.java b/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/LogoEntity.java new file mode 100644 index 000000000..4c47cc71e --- /dev/null +++ b/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/LogoEntity.java @@ -0,0 +1,124 @@ +/** + * 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.dao.model.nosql; + +import com.datastax.driver.core.utils.UUIDs; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.hashmapinc.server.common.data.Logo; +import com.hashmapinc.server.common.data.id.LogoId; +import com.hashmapinc.server.dao.model.BaseEntity; +import com.hashmapinc.server.dao.model.ModelConstants; + +import com.datastax.driver.mapping.annotations.Table; +import com.datastax.driver.mapping.annotations.Column; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.UUID; +import java.nio.ByteBuffer; + +import static com.hashmapinc.server.dao.model.ModelConstants.ID_PROPERTY; + +@Table(name = ModelConstants.LOGO_COLUMN_FAMILY_NAME) +@EqualsAndHashCode +@ToString + +public class LogoEntity implements BaseEntity{ + + @PartitionKey + @Column(name = ID_PROPERTY) + private UUID id; + + + @Column(name = ModelConstants.LOGO_NAME_PROPERTY) + private String name; + + @Column(name = ModelConstants.LOGO_DISPLAY_PROPERTY) + private boolean display; + + + @Column(name = ModelConstants.LOGO_FILE_PROPERTY) + private ByteBuffer file; + + + public LogoEntity() { + super(); + } + + public LogoEntity(Logo logo) { + if (logo.getId() != null) { + this.setId(logo.getId().getId()); + } + + this.name = logo.getName(); + this.display = logo.isDisplay(); + if (logo.getFile() != null) { + this.file = ByteBuffer.wrap(logo.getFile()); + } + + } + + @Override + public UUID getId() { + return id; + } + + @Override + public void setId(UUID id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isDisplay() { + return display; + } + + public void setDisplay(boolean display) { + this.display = display; + } + + public ByteBuffer getFile() { + return file; + } + + public void setFile(ByteBuffer file) { + this.file = file; + } + + @Override + public Logo toData() { + Logo logo = new Logo(new LogoId(getId())); + logo.setName(name); + logo.setDisplay(display); + if (file != null) { + byte[] fileByteArray = new byte[file.remaining()]; + file.get(fileByteArray); + logo.setFile(fileByteArray); + } + return logo; + } + + +} diff --git a/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/JpaLogoDao.java b/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/JpaLogoDao.java index b3f55aa54..64bc54925 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/JpaLogoDao.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/JpaLogoDao.java @@ -61,4 +61,16 @@ public Logo findById(String id) { } + @Override + public Logo findByName(String name) { + Logo logo = DaoUtil.getData(logoRepository.findByName(name)); + if (logo != null) { + return logo; + } else { + return null; + } + } + + + } diff --git a/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/LogoRepository.java b/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/LogoRepository.java index 4ea5e78b7..c5e126f09 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/LogoRepository.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/sql/logo/LogoRepository.java @@ -25,4 +25,6 @@ public interface LogoRepository extends CrudRepository { LogoEntity findById(String id); + + LogoEntity findByName(String name); } diff --git a/dao/src/main/java/com/hashmapinc/server/dao/theme/CassandraThemeDao.java b/dao/src/main/java/com/hashmapinc/server/dao/theme/CassandraThemeDao.java index d43ad3e24..31da31688 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/theme/CassandraThemeDao.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/theme/CassandraThemeDao.java @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + package com.hashmapinc.server.dao.theme; import com.hashmapinc.server.common.data.Theme; diff --git a/dao/src/main/java/com/hashmapinc/server/dao/theme/ThemeDao.java b/dao/src/main/java/com/hashmapinc/server/dao/theme/ThemeDao.java index 4ab45347b..18fd8f28a 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/theme/ThemeDao.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/theme/ThemeDao.java @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + package com.hashmapinc.server.dao.theme; import com.hashmapinc.server.common.data.Theme; import com.hashmapinc.server.dao.Dao; diff --git a/dao/src/main/resources/cassandra/upgrade/3.cql b/dao/src/main/resources/cassandra/upgrade/3.cql new file mode 100644 index 000000000..b0e4f01cc --- /dev/null +++ b/dao/src/main/resources/cassandra/upgrade/3.cql @@ -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. +-- + + +CREATE TABLE IF NOT EXISTS tempus.logo ( + id uuid, + name text, + enabled boolean, + file blob, + PRIMARY KEY (id,name) + ); diff --git a/dao/src/main/resources/sql/upgrade/5.sql b/dao/src/main/resources/sql/upgrade/5.sql new file mode 100644 index 000000000..3760094e3 --- /dev/null +++ b/dao/src/main/resources/sql/upgrade/5.sql @@ -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. +-- + + +CREATE TABLE IF NOT EXISTS logo ( + id varchar (31) NOT NULL CONSTRAINT logo_pkey PRIMARY KEY, + name varchar, + enabled boolean, + file varbinary + ); diff --git a/dao/src/test/java/com/hashmapinc/server/dao/JpaDaoTestSuite.java b/dao/src/test/java/com/hashmapinc/server/dao/JpaDaoTestSuite.java index f681a2c56..2d7f076da 100644 --- a/dao/src/test/java/com/hashmapinc/server/dao/JpaDaoTestSuite.java +++ b/dao/src/test/java/com/hashmapinc/server/dao/JpaDaoTestSuite.java @@ -33,7 +33,7 @@ public class JpaDaoTestSuite { 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/5.sql") ); } diff --git a/dao/src/test/java/com/hashmapinc/server/dao/NoSqlDaoServiceTestSuite.java b/dao/src/test/java/com/hashmapinc/server/dao/NoSqlDaoServiceTestSuite.java index 986f18bea..ab7831623 100644 --- a/dao/src/test/java/com/hashmapinc/server/dao/NoSqlDaoServiceTestSuite.java +++ b/dao/src/test/java/com/hashmapinc/server/dao/NoSqlDaoServiceTestSuite.java @@ -45,6 +45,11 @@ private static List getDataSetLists(){ dataSets.addAll(Arrays.asList( new ClassPathCQLDataSet("cassandra/upgrade/1.cql", false, false) )); + + dataSets.addAll(Arrays.asList( + new ClassPathCQLDataSet("cassandra/upgrade/3.cql", false, false) + )); + return dataSets; } diff --git a/dao/src/test/java/com/hashmapinc/server/dao/SqlDaoServiceTestSuite.java b/dao/src/test/java/com/hashmapinc/server/dao/SqlDaoServiceTestSuite.java index fe7ed2099..e2d3bbc9a 100644 --- a/dao/src/test/java/com/hashmapinc/server/dao/SqlDaoServiceTestSuite.java +++ b/dao/src/test/java/com/hashmapinc/server/dao/SqlDaoServiceTestSuite.java @@ -33,6 +33,6 @@ public class SqlDaoServiceTestSuite { 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/5.sql") ); } diff --git a/dao/src/test/java/com/hashmapinc/server/dao/service/AbstractServiceTest.java b/dao/src/test/java/com/hashmapinc/server/dao/service/AbstractServiceTest.java index 9d6c19ab3..6a2139769 100644 --- a/dao/src/test/java/com/hashmapinc/server/dao/service/AbstractServiceTest.java +++ b/dao/src/test/java/com/hashmapinc/server/dao/service/AbstractServiceTest.java @@ -28,6 +28,7 @@ import com.hashmapinc.server.dao.TagMetaData.TagMetaDataService; import com.hashmapinc.server.dao.cluster.NodeMetricService; import com.hashmapinc.server.dao.theme.ThemeService; +import com.hashmapinc.server.dao.logo.LogoService; import com.hashmapinc.server.dao.user.UserService; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -149,6 +150,11 @@ public abstract class AbstractServiceTest { @Autowired protected ThemeService themeService; + @Autowired + protected LogoService logoService; + + + class IdComparator> implements Comparator { diff --git a/dao/src/test/java/com/hashmapinc/server/dao/service/BaseLogoServiceTest.java b/dao/src/test/java/com/hashmapinc/server/dao/service/BaseLogoServiceTest.java new file mode 100644 index 000000000..191ec1305 --- /dev/null +++ b/dao/src/test/java/com/hashmapinc/server/dao/service/BaseLogoServiceTest.java @@ -0,0 +1,53 @@ +/** + * 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.dao.service; + +import com.hashmapinc.server.common.data.Logo; +import com.datastax.driver.core.utils.UUIDs; +import com.hashmapinc.server.common.data.UUIDConverter; +import com.hashmapinc.server.common.data.id.LogoId; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import java.util.List; +import java.util.Optional; + + +public class BaseLogoServiceTest extends AbstractServiceTest { + + @Test + public void saveLogo() 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); + + List logoNew = logoService.find(); + + Logo logoId = logoNew.get(0); + Assert.assertEquals(1, logoNew.size()); + + logoService.deleteLogoByName(logoId.getName()); + + } +} diff --git a/dao/src/test/java/com/hashmapinc/server/dao/service/nosql/LogoServiceNoSqlTest.java b/dao/src/test/java/com/hashmapinc/server/dao/service/nosql/LogoServiceNoSqlTest.java new file mode 100644 index 000000000..c843444a6 --- /dev/null +++ b/dao/src/test/java/com/hashmapinc/server/dao/service/nosql/LogoServiceNoSqlTest.java @@ -0,0 +1,25 @@ +/** + * 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.dao.service.nosql; + +import com.hashmapinc.server.dao.service.BaseLogoServiceTest; +import com.hashmapinc.server.dao.service.DaoNoSqlTest; + +@DaoNoSqlTest +public class LogoServiceNoSqlTest extends BaseLogoServiceTest { +} diff --git a/dao/src/test/java/com/hashmapinc/server/dao/service/sql/LogoServiceSqlTest.java b/dao/src/test/java/com/hashmapinc/server/dao/service/sql/LogoServiceSqlTest.java new file mode 100644 index 000000000..5439ebc3f --- /dev/null +++ b/dao/src/test/java/com/hashmapinc/server/dao/service/sql/LogoServiceSqlTest.java @@ -0,0 +1,27 @@ +/** + * 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.dao.service.sql; + +import com.hashmapinc.server.dao.service.DaoSqlTest; +import com.hashmapinc.server.dao.service.BaseLogoServiceTest; + +@DaoSqlTest + + +public class LogoServiceSqlTest extends BaseLogoServiceTest { +} diff --git a/dao/src/test/resources/sql/drop-all-tables.sql b/dao/src/test/resources/sql/drop-all-tables.sql index 1a53bc82c..62c8e7fc3 100644 --- a/dao/src/test/resources/sql/drop-all-tables.sql +++ b/dao/src/test/resources/sql/drop-all-tables.sql @@ -30,4 +30,5 @@ DROP TABLE IF EXISTS computation_job; DROP TABLE IF EXISTS installed_schema_versions; DROP TABLE IF EXISTS node_metric; DROP TABLE IF EXISTS theme; +DROP TABLE IF EXISTS logo; diff --git a/ui/src/app/admin/admin.controller.js b/ui/src/app/admin/admin.controller.js index e58903ec3..aabfc373f 100644 --- a/ui/src/app/admin/admin.controller.js +++ b/ui/src/app/admin/admin.controller.js @@ -17,7 +17,7 @@ import changeThemeTemplate from './change-theme.tpl.html'; /*@ngInject*/ -export default function AdminController(adminService, toast, $scope, $rootScope, $state, $translate, $mdDialog, $document,importExport) { +export default function AdminController(adminService, userService, toast, $scope, $rootScope, $state, $translate, $mdDialog, $document,importExport) { var vm = this; vm.save = save; @@ -27,6 +27,7 @@ export default function AdminController(adminService, toast, $scope, $rootScope, vm.changeDefaultTheme = changeDefaultTheme; vm.changeLogo = changeLogo; + $scope.selectedTheme = { }; vm.smtpProtocols = ('smtp smtps').split(' ').map(function (protocol) { @@ -87,6 +88,7 @@ export default function AdminController(adminService, toast, $scope, $rootScope, }); } + function cancel() { $mdDialog.cancel(); } @@ -112,7 +114,20 @@ export default function AdminController(adminService, toast, $scope, $rootScope, function changeLogo($event) { - importExport.importLogo($event) + importExport.importLogo($event).then(function success(logo) { + $rootScope.logo = logo.file; + var promise = userService.getLogo(); + if(promise) { + promise.then(function success(logo) { + $rootScope.logo = logo.file; + $rootScope.fileType = angular.lowercase(logo.name.substr(logo.name.lastIndexOf('.')+1)); + + }, + ) + } + }); + + } diff --git a/ui/src/app/api/admin.service.js b/ui/src/app/api/admin.service.js index c02653dd5..fb727e3e0 100644 --- a/ui/src/app/api/admin.service.js +++ b/ui/src/app/api/admin.service.js @@ -26,7 +26,8 @@ function AdminService($http, $q) { sendTestMail: sendTestMail, checkUpdates: checkUpdates, getAllThemes:getAllThemes, - saveThemeSettings:saveThemeSettings + saveThemeSettings:saveThemeSettings, + uploadLogo:uploadLogo } return service; @@ -42,6 +43,22 @@ function AdminService($http, $q) { return deferred.promise; } + function uploadLogo(file) { + var deferred = $q.defer(); + var url = '/api/settings/uploadLogo'; + var fd = new FormData(); + fd.append("file", file); + $http.post(url, fd, { + transformRequest: angular.identity, + headers: {'Content-Type': undefined} + }).then(function success(response) { + deferred.resolve(response.data); + }, function fail(response) { + deferred.reject(response.data); + }); + return deferred.promise; + } + function saveAdminSettings(settings) { var deferred = $q.defer(); var url = '/api/settings'; diff --git a/ui/src/app/api/user.service.js b/ui/src/app/api/user.service.js index b6e0c6d77..24540bdc3 100644 --- a/ui/src/app/api/user.service.js +++ b/ui/src/app/api/user.service.js @@ -60,7 +60,8 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, logi updateLastPublicDashboardId: updateLastPublicDashboardId, logout: logout, reloadUser: reloadUser, - getActivetheme:getActiveTheme + getActivetheme:getActiveTheme, + getLogo:getLogo } reloadUser(); @@ -89,6 +90,20 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, logi } + function getLogo() { + + var deferred = $q.defer(); + var url = 'api/logo/'; + $http.get(url, null).then(function success(response) { + deferred.resolve(response.data); + }, function fail() { + deferred.reject(); + }); + return deferred.promise; + + } + + function updateAndValidateToken(token, prefix, notify) { var valid = false; var tokenData = jwtHelper.decodeToken(token); diff --git a/ui/src/app/app.run.js b/ui/src/app/app.run.js index 9e5146736..0a4a9ac60 100644 --- a/ui/src/app/app.run.js +++ b/ui/src/app/app.run.js @@ -17,7 +17,7 @@ import Flow from '@flowjs/ng-flow/dist/ng-flow-standalone.min'; import UrlHandler from './url.handler'; /*@ngInject*/ -export default function AppRun($rootScope, $window, $injector, $location, $log, $state, $mdDialog, $filter, loginService, userService, $translate) { +export default function AppRun($rootScope, $window, $injector, $location, $state, $mdDialog, $filter, loginService, userService, $translate) { $window.Flow = Flow; var frame = null; @@ -31,6 +31,8 @@ export default function AppRun($rootScope, $window, $injector, $location, $log, var forbiddenDialog = null; $rootScope.iframeMode = false; + $rootScope.logo = ''; + $rootScope.fileType = ''; if (frame) { $rootScope.iframeMode = true; @@ -41,6 +43,7 @@ export default function AppRun($rootScope, $window, $injector, $location, $log, } } getdefaultTheme(); + getLogo(); initWatchers(); function getdefaultTheme() { @@ -54,6 +57,23 @@ export default function AppRun($rootScope, $window, $injector, $location, $log, } } + function getLogo() { + var promise = userService.getLogo(); + if(promise) { + promise.then(function success(logo) { + + if(logo != '') { + $rootScope.logo = logo.file; + $rootScope.fileType = angular.lowercase(logo.name.substr(logo.name.lastIndexOf('.')+1)); + + } + + }, + ) + } + } + + function initWatchers() { $rootScope.unauthenticatedHandle = $rootScope.$on('unauthenticated', function (event, doLogout) { if (doLogout) { diff --git a/ui/src/app/import-export/import-export.service.js b/ui/src/app/import-export/import-export.service.js index 0a98f67e1..fe33a4053 100644 --- a/ui/src/app/import-export/import-export.service.js +++ b/ui/src/app/import-export/import-export.service.js @@ -27,7 +27,7 @@ import entityAliasesTemplate from '../entity/alias/entity-aliases.tpl.html'; /*@ngInject*/ export default function ImportExport($log, $translate, $q, $mdDialog, $document, $http, itembuffer, utils, types, dashboardUtils, entityService, dashboardService, pluginService, ruleService, - widgetService, toast, attributeService,computationService, $window) { + widgetService, toast, attributeService,computationService,adminService,$window) { var service = { @@ -350,16 +350,18 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, function importLogo($event) { var deferred = $q.defer(); openImportDialog($event, 'admin.import', 'admin.logo-file').then( - function success(importData) { $log.log(importData); - // computationService.upload(importData.file).then( - // function success() { - // deferred.resolve(); - // - // }, - // function fail() { - // deferred.reject(); - // } - // ); + function success(importData) { + //return false; + adminService.uploadLogo(importData.file).then( + function success(response) { + + deferred.resolve(response); + + }, + function fail() { + deferred.reject(); + } + ); }, function fail() { deferred.reject(); diff --git a/ui/src/app/layout/home.tpl.html b/ui/src/app/layout/home.tpl.html index d05809f61..fa37c9fba 100755 --- a/ui/src/app/layout/home.tpl.html +++ b/ui/src/app/layout/home.tpl.html @@ -27,8 +27,14 @@
- -
+ + + +
- + + +