forked from onecx/onecx-theme-svc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
242 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/org/tkit/onecx/theme/rs/internal/services/ImagesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.tkit.onecx.theme.rs.internal.services; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.tkit.onecx.theme.domain.daos.ImageDAO; | ||
import org.tkit.onecx.theme.domain.models.Image; | ||
import org.tkit.onecx.theme.rs.internal.mappers.ImageMapper; | ||
|
||
import gen.org.tkit.onecx.image.rs.internal.model.ImageInfoDTO; | ||
import gen.org.tkit.onecx.image.rs.internal.model.RefTypeDTO; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@ApplicationScoped | ||
public class ImagesService { | ||
|
||
@Context | ||
HttpHeaders httpHeaders; | ||
|
||
@Inject | ||
ImageMapper imageMapper; | ||
|
||
@Inject | ||
ImageDAO imageDAO; | ||
|
||
public ImageInfoDTO uploadImage(Integer contentLength, String refId, RefTypeDTO refType, byte[] body) { | ||
var contentType = httpHeaders.getMediaType(); | ||
contentType = new MediaType(contentType.getType(), contentType.getSubtype()); | ||
var image = imageMapper.create(refId, refType.toString(), contentType.toString(), contentLength); | ||
image.setLength(contentLength); | ||
image.setImageData(body); | ||
image = imageDAO.create(image); | ||
|
||
return imageMapper.map(image); | ||
} | ||
|
||
public Image updateImage(String refId, RefTypeDTO refType, byte[] body, Integer contentLength) { | ||
Image image = imageDAO.findByRefIdAndRefType(refId, refType.toString()); | ||
if (image == null) { | ||
System.out.println("ITS NULLLLLLL_____________"); | ||
return null; | ||
} | ||
|
||
var contentType = httpHeaders.getMediaType(); | ||
contentType = new MediaType(contentType.getType(), contentType.getSubtype()); | ||
|
||
image.setLength(contentLength); | ||
image.setMimeType(contentType.toString()); | ||
image.setImageData(body); | ||
|
||
return imageDAO.update(image); | ||
} | ||
|
||
@Transactional | ||
public void deleteImage(String refId, RefTypeDTO refType) { | ||
|
||
imageDAO.deleteQueryByRefIdAndRefType(refId, refType); | ||
} | ||
|
||
@Transactional | ||
public void deleteImagesById(String refId) { | ||
|
||
try { | ||
imageDAO.deleteQueryByRefId(refId); | ||
}catch (Exception e){ | ||
System.out.println("NO DEL SUCCESS_______"); | ||
} | ||
|
||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/tkit/onecx/theme/rs/internal/services/ThemesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.tkit.onecx.theme.rs.internal.services; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
|
||
import org.tkit.onecx.theme.domain.daos.ImageDAO; | ||
import org.tkit.onecx.theme.domain.daos.ThemeDAO; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@ApplicationScoped | ||
public class ThemesService { | ||
|
||
@Inject | ||
ThemeDAO dao; | ||
|
||
@Inject | ||
ImageDAO imageDAO; | ||
|
||
@Transactional | ||
public void deleteTheme(String id) { | ||
|
||
var image = dao.findById(id); | ||
if (image != null) { | ||
dao.deleteQueryById(id); | ||
|
||
// workaround for images | ||
imageDAO.deleteQueryByRefId(image.getName()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.