Skip to content

Commit

Permalink
Merge branch 'main' into issue-31420-datetool
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms authored Feb 24, 2025
2 parents 20111d1 + f70861e commit 04a4f40
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class UniqueFieldDataBaseUtil {


private final static String GET_UNIQUE_FIELDS_BY_CONTENTLET_AND_LANGUAGE = "SELECT * FROM unique_fields " +
"WHERE supporting_values->'" + CONTENTLET_IDS_ATTR + "' @> ?::jsonb AND (supporting_values->>'" + LANGUAGE_ID_ATTR +"')::INTEGER = ?";
"WHERE supporting_values->'" + CONTENTLET_IDS_ATTR + "' @> ?::jsonb AND (supporting_values->>'" + LANGUAGE_ID_ATTR +"')::BIGINT = ?";

private final static String GET_UNIQUE_FIELDS_BY_CONTENTLET_AND_VARIANT= "SELECT * FROM unique_fields " +
"WHERE supporting_values->'" + CONTENTLET_IDS_ATTR + "' @> ?::jsonb AND supporting_values->>'" + VARIANT_ATTR + "' = ?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.util.Logger;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
Expand Down Expand Up @@ -69,13 +70,20 @@ public void cleanUpAfterDeleteContentlet(final DeleteContentletVersionInfoEvent
final ContentType contentType = APILocator.getContentTypeAPI(APILocator.systemUser())
.find(contentlet.getContentTypeId());

Logger.debug(UniqueFieldsTableCleaner.class, "Cleaning up Content Type with id " + contentlet.getContentTypeId());

boolean hasUniqueField = hasUniqueField(contentType);

Logger.info(UniqueFieldsTableCleaner.class, "Has unique field: " + hasUniqueField);

if (hasUniqueField) {
uniqueFieldValidationStrategyResolver.get().cleanUp(contentlet, event.isDeleteAllVariant());
}
} catch (DotSecurityException e) {
throw new DotRuntimeException(e);
} catch (Exception e) {
Logger.error(UniqueFieldsTableCleaner.class, e);
throw new DotDataException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
import static com.dotcms.content.elasticsearch.business.ESContentletAPIImpl.UNIQUE_PER_SITE_FIELD_VARIABLE_NAME;
import static com.dotcms.contenttype.business.uniquefields.extratable.UniqueFieldCriteria.*;
import static com.dotcms.util.CollectionsUtils.list;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

@ApplicationScoped
@RunWith(JUnit4WeldRunner.class)
Expand Down Expand Up @@ -652,4 +650,45 @@ private List<Map<String, Object>> getUniqueFieldsRegisters(ContentType contentTy
.addParam(contentType.id()).loadObjectResults();
}

/**
* Method to test: {@link UniqueFieldDataBaseUtil#get(String, long)}
* when: Try to get the Unique value using a too long language ID
* should: get the register and not throw any exception
*
* @throws IOException
* @throws DotDataException
*/
@Test
public void getUniqueValueWithLanguageWithTooLongId() throws IOException, DotDataException {
final String defaultUniqueValue = "default_variant_unique_value";

final ContentType contentType = new ContentTypeDataGen()
.nextPersisted();

final Language language = new LanguageDataGen().nextPersisted();

final Field uniqueTextField = new FieldDataGen()
.contentTypeId(contentType.id())
.unique(true)
.type(TextField.class)
.nextPersisted();

final Host host = new SiteDataGen().nextPersisted();

final Contentlet defaultContentlet = new ContentletDataGen(contentType)
.host(host)
.languageId(language.getId())
.setProperty(uniqueTextField.variable(), defaultUniqueValue)
.nextPersisted();

final UniqueFieldDataBaseUtil uniqueFieldDataBaseUtil = new UniqueFieldDataBaseUtil();
final String supportingValueJSON = "{\"live\": true, \"siteId\": \"SYSTEM_HOST\", \"variant\": \"DEFAULT\", \"fieldValue\": \"System Host\", \"languageId\": 1565640883097, \"contentTypeId\": \"855a2d72-f2f3-4169-8b04-ac5157c4380c\", \"contentletIds\": [\"" + defaultContentlet.getIdentifier() + "\"], \"uniquePerSite\": false, \"fieldVariableName\": \"hostName\"}";
final Map<String, Object> jsonFromString = JsonUtil.getJsonFromString(supportingValueJSON);

uniqueFieldDataBaseUtil.insert("1", jsonFromString);

List<Map<String, Object>> maps = uniqueFieldDataBaseUtil.get(defaultContentlet.getIdentifier(), language.getId());
assertNotNull(maps);
}

}

0 comments on commit 04a4f40

Please sign in to comment.