catch up with branch daily
Signed-off-by: Ralf Mollik <ramollik@compex-commerce.com>
diff --git a/org.eclipse.osbp.blob/META-INF/MANIFEST.MF b/org.eclipse.osbp.blob/META-INF/MANIFEST.MF
index 026e517..e4c701f 100644
--- a/org.eclipse.osbp.blob/META-INF/MANIFEST.MF
+++ b/org.eclipse.osbp.blob/META-INF/MANIFEST.MF
@@ -27,12 +27,13 @@
org.eclipse.persistence.core;bundle-version="2.6.1",
org.eclipse.persistence.jpa;bundle-version="2.6.1",
org.eclipse.osbp.preferences;bundle-version="0.9.0",
- org.eclipse.osbp.xtext.i18n;bundle-version="0.9.0"
+ org.eclipse.osbp.xtext.i18n;bundle-version="0.9.0",
+ org.eclipse.e4.core.contexts,
+ org.eclipse.osbp.ui.api
Bundle-Vendor: Eclipse OSBP
Import-Package: com.vaadin.ui,
org.eclipse.e4.ui.di,
- org.eclipse.osbp.core.api.persistence;version="0.9.0",
- org.eclipse.osbp.ui.api.customfields
+ org.eclipse.osbp.core.api.persistence;version="0.9.0"
Service-Component: OSGI-INF/*.xml
Factory-Model: datatype,
entity,
diff --git a/org.eclipse.osbp.blob/build.properties b/org.eclipse.osbp.blob/build.properties
index 3ae14f2..ef84761 100644
--- a/org.eclipse.osbp.blob/build.properties
+++ b/org.eclipse.osbp.blob/build.properties
@@ -9,6 +9,7 @@
.,\
OSGI-INF/,\
i18n/,\
+ images/,\
license.html,\
LICENSE.txt,\
epl-2.0.html
diff --git a/org.eclipse.osbp.blob/i18n/I18N_de_AT.properties b/org.eclipse.osbp.blob/i18n/I18N_de_AT.properties
deleted file mode 100644
index 6c73e1d..0000000
--- a/org.eclipse.osbp.blob/i18n/I18N_de_AT.properties
+++ /dev/null
@@ -1 +0,0 @@
-#de_AT
diff --git a/org.eclipse.osbp.blob/i18n/I18N_en_US.properties b/org.eclipse.osbp.blob/i18n/I18N_en_US.properties
deleted file mode 100644
index d89e21c..0000000
--- a/org.eclipse.osbp.blob/i18n/I18N_en_US.properties
+++ /dev/null
@@ -1 +0,0 @@
-#en_US
diff --git a/org.eclipse.osbp.blob/images/download.png b/org.eclipse.osbp.blob/images/download.png
new file mode 100644
index 0000000..360db9d
--- /dev/null
+++ b/org.eclipse.osbp.blob/images/download.png
Binary files differ
diff --git a/org.eclipse.osbp.blob/images/upload.png b/org.eclipse.osbp.blob/images/upload.png
new file mode 100644
index 0000000..d9ec1c4
--- /dev/null
+++ b/org.eclipse.osbp.blob/images/upload.png
Binary files differ
diff --git a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/BlobMappingDto.java b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/BlobMappingDto.java
index 30f1ee0..6534f76 100644
--- a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/BlobMappingDto.java
+++ b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/BlobMappingDto.java
@@ -1,16 +1,3 @@
-/**
- * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
- */
package org.eclipse.osbp.blob.dtos;
import java.beans.PropertyChangeListener;
@@ -60,9 +47,9 @@
*
*/
protected void installLazyCollections() {
- blobsRef = new org.eclipse.osbp.dsl.dto.lib.OppositeContainmentDtoList<>(
+ blobsRef = new org.eclipse.osbp.dsl.dto.lib.OppositeDtoList<>(
org.eclipse.osbp.dsl.dto.lib.MappingContext.getCurrent(),
- BlobDto.class, this, "blobMapping.id",
+ BlobDto.class, "blobMapping.id",
(java.util.function.Supplier<Object> & Serializable) () -> this.getId(), this);
}
@@ -149,20 +136,7 @@
if (isDisposed()) {
return;
}
- try {
- // Dispose all the composition references.
- if (this.blobsRef != null) {
- for (BlobDto blobDto : this.blobsRef) {
- blobDto.dispose();
- }
- this.blobsRef = null;
- }
-
- }
- finally {
- firePropertyChange("disposed", this.disposed, this.disposed = true);
- }
-
+ firePropertyChange("disposed", this.disposed, this.disposed = true);
}
/**
@@ -292,7 +266,6 @@
public void internalAddToBlobsRef(final BlobDto blobDto) {
if(!org.eclipse.osbp.dsl.dto.lib.MappingContext.isMappingMode()) {
- if(!internalGetBlobsRef().contains(blobDto)) {
List<BlobDto> oldList = null;
if(internalGetBlobsRef() instanceof org.eclipse.osbp.dsl.dto.lib.AbstractOppositeDtoList) {
oldList = ((org.eclipse.osbp.dsl.dto.lib.AbstractOppositeDtoList) internalGetBlobsRef()).copy();
@@ -301,7 +274,6 @@
}
internalGetBlobsRef().add(blobDto);
firePropertyChange("blobsRef", oldList, internalGetBlobsRef());
- }
}
}
diff --git a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/BlobTypingDto.java b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/BlobTypingDto.java
index e6d11c7..c8d3302 100644
--- a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/BlobTypingDto.java
+++ b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/BlobTypingDto.java
@@ -1,16 +1,3 @@
-/**
- * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
- */
package org.eclipse.osbp.blob.dtos;
import java.beans.PropertyChangeListener;
@@ -227,9 +214,7 @@
public void addToNormalizer(final NormalizerResolutionDto normalizerResolutionDto) {
checkDisposed();
- if(!internalGetNormalizer().contains(normalizerResolutionDto)){
- internalAddToNormalizer(normalizerResolutionDto);
- }
+ internalAddToNormalizer(normalizerResolutionDto);
}
public void removeFromNormalizer(final NormalizerResolutionDto normalizerResolutionDto) {
@@ -246,7 +231,6 @@
normalizerResolutionDto.addPropertyChangeListener(this);
if(!org.eclipse.osbp.dsl.dto.lib.MappingContext.isMappingMode()) {
- if(!internalGetNormalizer().contains(normalizerResolutionDto)) {
List<NormalizerResolutionDto> oldList = null;
if(internalGetNormalizer() instanceof org.eclipse.osbp.dsl.dto.lib.AbstractOppositeDtoList) {
oldList = ((org.eclipse.osbp.dsl.dto.lib.AbstractOppositeDtoList) internalGetNormalizer()).copy();
@@ -255,7 +239,6 @@
}
internalGetNormalizer().add(normalizerResolutionDto);
firePropertyChange("normalizer", oldList, internalGetNormalizer());
- }
}
}
diff --git a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/MimeTypeDto.java b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/MimeTypeDto.java
index b766e92..d1fdd57 100644
--- a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/MimeTypeDto.java
+++ b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/dtos/MimeTypeDto.java
@@ -1,16 +1,3 @@
-/**
- * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
- */
package org.eclipse.osbp.blob.dtos;
import java.beans.PropertyChangeListener;
@@ -205,9 +192,7 @@
public void addToContentTypeList(final ContentTypeDto contentTypeDto) {
checkDisposed();
- if(!internalGetContentTypeList().contains(contentTypeDto)){
- internalAddToContentTypeList(contentTypeDto);
- }
+ internalAddToContentTypeList(contentTypeDto);
}
public void removeFromContentTypeList(final ContentTypeDto contentTypeDto) {
@@ -224,7 +209,6 @@
contentTypeDto.addPropertyChangeListener(this);
if(!org.eclipse.osbp.dsl.dto.lib.MappingContext.isMappingMode()) {
- if(!internalGetContentTypeList().contains(contentTypeDto)) {
List<ContentTypeDto> oldList = null;
if(internalGetContentTypeList() instanceof org.eclipse.osbp.dsl.dto.lib.AbstractOppositeDtoList) {
oldList = ((org.eclipse.osbp.dsl.dto.lib.AbstractOppositeDtoList) internalGetContentTypeList()).copy();
@@ -233,7 +217,6 @@
}
internalGetContentTypeList().add(contentTypeDto);
firePropertyChange("contentTypeList", oldList, internalGetContentTypeList());
- }
}
}
diff --git a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/Blob.java b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/Blob.java
index cb98f8e..d646cca 100644
--- a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/Blob.java
+++ b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/Blob.java
@@ -1,16 +1,3 @@
-/**
- * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
- */
package org.eclipse.osbp.blob.entities;
import javax.persistence.Basic;
@@ -51,7 +38,7 @@
@Column(name = "RESOLUTION_ID")
private int resolutionId;
- @ManyToOne
+ @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "BLOB_MAPPING_ID")
private BlobMapping blobMapping;
@@ -88,18 +75,7 @@
if (isDisposed()) {
return;
}
- try {
- // Dispose all the composition references.
- if (this.blobMapping != null) {
- this.blobMapping.dispose();
- this.blobMapping = null;
- }
-
- }
- finally {
- disposed = true;
- }
-
+ disposed = true;
}
/**
diff --git a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/BlobMapping.java b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/BlobMapping.java
index 5d9358e..8394251 100644
--- a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/BlobMapping.java
+++ b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/BlobMapping.java
@@ -1,16 +1,3 @@
-/**
- * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
- */
package org.eclipse.osbp.blob.entities;
import java.util.ArrayList;
@@ -30,7 +17,6 @@
import org.eclipse.osbp.blob.entities.Blob;
import org.eclipse.osbp.dsl.common.datatypes.IEntity;
import org.eclipse.osbp.runtime.common.annotations.Dispose;
-import org.eclipse.persistence.annotations.Noncacheable;
@Entity
@Table(name = "BLOB_MAPPING")
@@ -54,8 +40,7 @@
private int mimeTypeId;
@JoinColumn(name = "BLOBS_REF_ID")
- @OneToMany(mappedBy = "blobMapping", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
- @Noncacheable
+ @OneToMany(mappedBy = "blobMapping", cascade = { CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST }, orphanRemoval = true, fetch = FetchType.EAGER)
private List<Blob> blobsRef;
/**
@@ -238,9 +223,7 @@
return;
}
- if(!internalGetBlobsRef().contains(blob)) {
- internalGetBlobsRef().add(blob);
- }
+ internalGetBlobsRef().add(blob);
}
/**
diff --git a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/BlobTyping.java b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/BlobTyping.java
index 3a19aa7..712fbe2 100644
--- a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/BlobTyping.java
+++ b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/BlobTyping.java
@@ -1,16 +1,3 @@
-/**
- * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
- */
package org.eclipse.osbp.blob.entities;
import java.io.Serializable;
@@ -209,9 +196,7 @@
return;
}
- if(!internalGetNormalizer().contains(normalizerResolution)) {
- internalGetNormalizer().add(normalizerResolution);
- }
+ internalGetNormalizer().add(normalizerResolution);
}
/**
diff --git a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/MimeType.java b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/MimeType.java
index 0b574a5..9df2bfe 100644
--- a/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/MimeType.java
+++ b/org.eclipse.osbp.blob/src-gen/org/eclipse/osbp/blob/entities/MimeType.java
@@ -1,16 +1,3 @@
-/**
- * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
- */
package org.eclipse.osbp.blob.entities;
import java.io.Serializable;
@@ -200,9 +187,7 @@
return;
}
- if(!internalGetContentTypeList().contains(contentType)) {
- internalGetContentTypeList().add(contentType);
- }
+ internalGetContentTypeList().add(contentType);
}
/**
diff --git a/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/Blob.entity b/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/Blob.entity
index 87d7703..33e098a 100644
--- a/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/Blob.entity
+++ b/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/Blob.entity
@@ -78,7 +78,7 @@
var String uniqueName
var String fileName
var int mimeTypeId
- ref cascade Blob[*] blobsRef opposite blobMapping
+ ref cascadeMergePersist cascadeRemove Blob[*] blobsRef opposite blobMapping
}
entity Blob {
diff --git a/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/component/BlobUploadComponent.java b/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/component/BlobUploadComponent.java
index 75b2141..84b7136 100644
--- a/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/component/BlobUploadComponent.java
+++ b/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/component/BlobUploadComponent.java
@@ -19,25 +19,26 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Locale;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.osbp.blob.service.BlobService;
import org.eclipse.osbp.ui.api.customfields.IBlobEvent;
import org.eclipse.osbp.ui.api.customfields.IBlobService;
import org.eclipse.osbp.ui.api.customfields.IBlobUploadEventListener;
+import org.eclipse.osbp.ui.api.metadata.IDSLMetadataService;
+import org.eclipse.osbp.ui.api.user.IUser;
import com.vaadin.server.Extension;
import com.vaadin.server.FileDownloader;
-import com.vaadin.server.Resource;
import com.vaadin.server.StreamResource;
+import com.vaadin.server.ThemeResource;
import com.vaadin.ui.AbstractLayout;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomField;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
-import com.vaadin.ui.Notification;
-import com.vaadin.ui.Notification.Type;
import com.wcs.wcslib.vaadin.widget.multifileupload.ui.MultiFileUpload;
import com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadFinishedHandler;
@@ -66,34 +67,38 @@
* @author dominguez
*
*/
-public class BlobUploadComponent extends CustomField<String> implements IBlobUploadEventListener {
+public class BlobUploadComponent extends CustomField<String> implements IBlobUploadEventListener, IUser.UserLocaleListener {
+ private static final String DOWNLOAD = "download";
+ private static final String UPLOAD = "upload";
/**
*
*/
private static final long serialVersionUID = -3890298210810421764L;
-
+ private static final String ICONPATH = "plugin/org.eclipse.osbp.blob/images/%s.png";
+
public enum BUTTON_ALIGNMENT {
TOP, BUTTOM, LEFT, RIGHT, DEFAULT
}
private transient IEventBroker eventBroker = null;
private static final int DEFAULT_RESOLUTION_ID = 0;
- private transient IBlobService blobService;
private BlobUploadButton singleUpload;
private Button downloadButton;
private Label displayImageLabel;
private Label blobUploadCompLabel = null;
private AbstractLayout layout = null;
-
private int displayResolutionId = DEFAULT_RESOLUTION_ID;
private BUTTON_ALIGNMENT buttonAlignment = BUTTON_ALIGNMENT.RIGHT;
-
- private Resource uploadIcon;
- private Resource downloadIcon;
private String lastUploadedFilename;
- public BlobUploadComponent(IBlobService blobService) {
+ private transient IBlobService blobService;
+ private transient IDSLMetadataService dslMetadataService;
+ private transient IUser user;
+
+ public BlobUploadComponent(IBlobService blobService, IDSLMetadataService dslMetadataService, IUser user) {
+ this.dslMetadataService = dslMetadataService;
+ this.user = user;
this.blobService = blobService;
}
@@ -135,20 +140,16 @@
};
singleUpload = new BlobUploadButton(handler);
- if (uploadIcon != null) {
- singleUpload.setUploadButtonIcon(uploadIcon);
- } else {
- singleUpload.setUploadButtonCaption("upload");
- }
+ singleUpload.setUploadButtonIcon(new ThemeResource(String.format(ICONPATH, UPLOAD)));
+ singleUpload.setDescription(dslMetadataService.translate(user.getLocale().toLanguageTag(), UPLOAD));
+ singleUpload.setUploadButtonCaption(" ");
+
// a Button is still active if the component is read only.
if (isReadOnly()) {
singleUpload.setEnabled(false);
}
- if (downloadIcon != null) {
- downloadButton = new Button(downloadIcon);
- } else {
- downloadButton = new Button("download");
- }
+ downloadButton = new Button(new ThemeResource(String.format(ICONPATH, DOWNLOAD)));
+ downloadButton.setDescription(dslMetadataService.translate(user.getLocale().toLanguageTag(), DOWNLOAD));
downloadButton.setVisible(false);
downloadButton.setEnabled(false);
}
@@ -284,14 +285,6 @@
singleUpload.setUploadButtonCaption(buttonCaption);
}
- public void setUploadIcon(Resource uploadIcon) {
- this.uploadIcon = uploadIcon;
- }
-
- public void setDownloadIcon(Resource downloadIcon) {
- this.downloadIcon = downloadIcon;
- }
-
public void setUploadAcceptedMimeTypes(List<String> mimeTypes) {
singleUpload.setUploadAcceptedMimeTypes(mimeTypes);
}
@@ -308,11 +301,13 @@
public void attach() {
super.attach();
blobService.addBlobUploadListener(this);
+ user.addUserLocaleListener(this);
}
@Override
public void detach() {
blobService.removeBlobUploadListener((IBlobUploadEventListener) this);
+ user.removeUserLocaleListener(this);
super.detach();
}
@@ -324,8 +319,6 @@
if (eventBroker != null) {
eventBroker.send(IBlobEvent.STOPPED_BLOB_UPLOAD, getValue());
}
-// } else {
-// Notification.show("Blob NOT successfully uploaded. Error: " + e.getErrorMessage(), Type.ERROR_MESSAGE);
}
}
@@ -333,4 +326,12 @@
public void focus() {
super.focus();
}
+
+ @Override
+ public void localeChanged(Locale locale) {
+ if(singleUpload != null && downloadButton != null) {
+ singleUpload.setDescription(dslMetadataService.translate(user.getLocale().toLanguageTag(), UPLOAD));
+ downloadButton.setDescription(dslMetadataService.translate(user.getLocale().toLanguageTag(), DOWNLOAD));
+ }
+ }
}
diff --git a/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/service/BlobService.java b/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/service/BlobService.java
index c07497d..209ec82 100644
--- a/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/service/BlobService.java
+++ b/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/service/BlobService.java
@@ -23,6 +23,9 @@
import java.io.InputStream;
import java.sql.Blob;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageIO;
@@ -34,7 +37,11 @@
import org.eclipse.osbp.blob.dtos.BlobDto;
import org.eclipse.osbp.blob.dtos.BlobMappingDto;
import org.eclipse.osbp.dsl.dto.lib.impl.DtoServiceAccess;
+import org.eclipse.osbp.jpa.services.Query;
+import org.eclipse.osbp.jpa.services.filters.LAnd;
+import org.eclipse.osbp.jpa.services.filters.LCompare;
import org.eclipse.osbp.runtime.common.filter.IDTOServiceWithMutablePersistence;
+import org.eclipse.osbp.runtime.common.filter.IQuery;
import org.eclipse.osbp.ui.api.customfields.IBlobEvent;
import org.eclipse.osbp.ui.api.customfields.IBlobService;
import org.eclipse.osbp.ui.api.customfields.IBlobTyping;
@@ -340,6 +347,18 @@
return null;
}
+ private BlobDto getBlobByName(String blobMappingName, int resolutionId, int mimeTypeId) {
+ if (blobMappingName != null && resolutionId >= 0) {
+ IQuery query = new Query(new LAnd(new LCompare.Equal("fileName", blobMappingName), new LCompare.Equal("mimeTypeId", mimeTypeId)));
+ Collection<BlobMappingDto> blobMappings = dtoBlobMappingDtoService.find(query);
+ if (!blobMappings.isEmpty()) {
+ Iterator<BlobMappingDto> iter = blobMappings.iterator();
+ return getBlobByResolution(resolutionId, iter.next());
+ }
+ }
+ return null;
+ }
+
private BlobDto getBlobByResolution(int resolutionId, BlobMappingDto blobMapping) {
for (BlobDto blob : blobMapping.getBlobsRef()) {
if (isImage(blobMapping.getMimeTypeId())) {
@@ -594,6 +613,38 @@
}
@Override
+ public String getBase64Image(String uuid, int resolutionId) {
+ BlobDto blob = getBlobById(uuid, resolutionId);
+ if (blob != null) {
+ return Arrays.toString(blob.getData());
+ }
+ return null;
+ }
+
+ @Override
+ public BufferedImage getBufferedImageByName(String name, int resolutionId, String mimeType) {
+ BlobDto blob = getBlobByName(name, resolutionId, blobAPI.getMimeTypeContentTypeId(mimeType));
+ if (blob != null) {
+ InputStream in = new ByteArrayInputStream(decodeBase64(blob.getData()));
+ try {
+ return ImageIO.read(in);
+ } catch (IOException e) {
+ // bad luck
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String getBase64ImageByName(String name, int resolutionId, String mimeType) {
+ BlobDto blob = getBlobByName(name, resolutionId, blobAPI.getMimeTypeContentTypeId(mimeType));
+ if (blob != null) {
+ return Arrays.toString(blob.getData());
+ }
+ return null;
+ }
+
+ @Override
public byte[] getByteArrayImage(String uuid, int resolutionId) {
BlobDto blob = getBlobById(uuid, resolutionId);
if (blob != null) {
diff --git a/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/service/BlobTypingAPI.java b/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/service/BlobTypingAPI.java
index 60cc961..544f925 100644
--- a/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/service/BlobTypingAPI.java
+++ b/org.eclipse.osbp.blob/src/org/eclipse/osbp/blob/service/BlobTypingAPI.java
@@ -239,10 +239,14 @@
*/
@Override
public int getMimeTypeContentTypeId(String contentTypeStr) {
+ String type = contentTypeStr;
+ if("image/jpg".contentEquals(contentTypeStr)) {
+ type = "image/jpeg";
+ }
BlobTyping lblobTyping = getBlobTyping();
if (lblobTyping != null) {
for (ContentType contentType : lblobTyping.getMimeType().getContentTypeList()) {
- if (contentTypeStr.equals(contentType.getType())) {
+ if (type.equals(contentType.getType())) {
return contentType.getId();
}
}