Skip to content

Commit 1e36c54

Browse files
MrJohn1911brianchandotcom
authored andcommitted
LPD-84165 feat: delete object entry and index
1 parent 0bffcd4 commit 1e36c54

3 files changed

Lines changed: 72 additions & 7 deletions

File tree

modules/dxp/apps/ai-hub/ai-hub-rest-api/src/main/java/com/liferay/ai/hub/rest/manager/v1_0/ContentRetrieverManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
public interface ContentRetrieverManager {
1515

16+
public void deleteContentRetriever(
17+
long companyId, DTOConverterContext dtoConverterContext,
18+
String externalReferenceCode)
19+
throws Exception;
20+
1621
public ContentRetriever postContentRetriever(
1722
long companyId, ContentRetriever contentRetriever,
1823
DTOConverterContext dtoConverterContext)

modules/dxp/apps/ai-hub/ai-hub-rest-impl/src/main/java/com/liferay/ai/hub/rest/internal/manager/v1_0/ContentRetrieverManagerImpl.java

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.liferay.ai.hub.rest.dto.v1_0.ContentRetriever;
1010
import com.liferay.ai.hub.rest.manager.v1_0.ContentRetrieverManager;
1111
import com.liferay.ai.hub.util.AccountEntryUtil;
12+
import com.liferay.object.model.ObjectDefinition;
1213
import com.liferay.object.rest.dto.v1_0.ObjectEntry;
1314
import com.liferay.object.rest.manager.v1_0.ObjectEntryManager;
1415
import com.liferay.object.service.ObjectDefinitionLocalService;
@@ -21,6 +22,7 @@
2122
import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
2223
import com.liferay.portal.search.engine.adapter.SearchEngineAdapter;
2324
import com.liferay.portal.search.engine.adapter.index.CreateIndexRequest;
25+
import com.liferay.portal.search.engine.adapter.index.DeleteIndexRequest;
2426
import com.liferay.portal.search.engine.adapter.index.IndicesExistsIndexRequest;
2527
import com.liferay.portal.search.engine.adapter.index.IndicesExistsIndexResponse;
2628
import com.liferay.portal.search.index.IndexNameBuilder;
@@ -40,6 +42,24 @@
4042
@Component(service = ContentRetrieverManager.class)
4143
public class ContentRetrieverManagerImpl implements ContentRetrieverManager {
4244

45+
@Override
46+
public void deleteContentRetriever(
47+
long companyId, DTOConverterContext dtoConverterContext,
48+
String externalReferenceCode)
49+
throws Exception {
50+
51+
ObjectEntry objectEntry = _objectEntryManager.getObjectEntry(
52+
companyId, dtoConverterContext, externalReferenceCode,
53+
_getObjectDefinition(companyId), null);
54+
55+
_removeIndex(
56+
GetterUtil.getString(objectEntry.getPropertyValue("indexName")));
57+
58+
_objectEntryManager.deleteObjectEntry(
59+
companyId, dtoConverterContext, externalReferenceCode,
60+
_getObjectDefinition(companyId), null);
61+
}
62+
4363
@Override
4464
public ContentRetriever postContentRetriever(
4565
long companyId, ContentRetriever contentRetriever,
@@ -90,13 +110,7 @@ public ContentRetriever postContentRetriever(
90110
}
91111

92112
private void _createIndex(String indexName) throws Exception {
93-
IndicesExistsIndexRequest indicesExistsIndexRequest =
94-
new IndicesExistsIndexRequest(indexName);
95-
96-
IndicesExistsIndexResponse indicesExistsIndexResponse =
97-
_searchEngineAdapter.execute(indicesExistsIndexRequest);
98-
99-
if (indicesExistsIndexResponse.isExists()) {
113+
if (_hasIndex(indexName)) {
100114
return;
101115
}
102116

@@ -110,13 +124,38 @@ private void _createIndex(String indexName) throws Exception {
110124
_searchEngineAdapter.execute(createIndexRequest);
111125
}
112126

127+
private ObjectDefinition _getObjectDefinition(long companyId)
128+
throws Exception {
129+
130+
return _objectDefinitionLocalService.getObjectDefinition(
131+
companyId, "AIHubContentRetriever");
132+
}
133+
134+
private boolean _hasIndex(String indexName) {
135+
IndicesExistsIndexRequest indicesExistsIndexRequest =
136+
new IndicesExistsIndexRequest(indexName);
137+
138+
IndicesExistsIndexResponse indicesExistsIndexResponse =
139+
_searchEngineAdapter.execute(indicesExistsIndexRequest);
140+
141+
return indicesExistsIndexResponse.isExists();
142+
}
143+
113144
private String _readJSON(String fileName) throws Exception {
114145
JSONObject jsonObject = _jsonFactory.createJSONObject(
115146
StringUtil.read(getClass(), "/META-INF/search/" + fileName));
116147

117148
return jsonObject.toString();
118149
}
119150

151+
private void _removeIndex(String indexName) {
152+
if (!_hasIndex(indexName)) {
153+
return;
154+
}
155+
156+
_searchEngineAdapter.execute(new DeleteIndexRequest(indexName));
157+
}
158+
120159
private ContentRetriever _toContentRetriever(ObjectEntry objectEntry) {
121160
return new ContentRetriever() {
122161
{

modules/dxp/apps/ai-hub/ai-hub-rest-impl/src/main/java/com/liferay/ai/hub/rest/internal/resource/v1_0/ContentRetrieverResourceImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@
2626
public class ContentRetrieverResourceImpl
2727
extends BaseContentRetrieverResourceImpl {
2828

29+
@Override
30+
public void deleteContentRetrieverByExternalReferenceCode(
31+
String externalReferenceCode)
32+
throws Exception {
33+
34+
if (!FeatureFlagManagerUtil.isEnabled(
35+
contextCompany.getCompanyId(), "LPD-62272")) {
36+
37+
throw new UnsupportedOperationException();
38+
}
39+
40+
_contentRetrieverManager.deleteContentRetriever(
41+
contextCompany.getCompanyId(),
42+
new DefaultDTOConverterContext(
43+
contextAcceptLanguage.isAcceptAllLanguages(), null,
44+
_dtoConverterRegistry, contextHttpServletRequest, null,
45+
contextAcceptLanguage.getPreferredLocale(), contextUriInfo,
46+
contextUser),
47+
externalReferenceCode);
48+
}
49+
2950
@Override
3051
public ContentRetriever postContentRetriever(
3152
ContentRetriever contentRetriever)

0 commit comments

Comments
 (0)