Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dotCMS/core.git
Browse files Browse the repository at this point in the history
  • Loading branch information
agomez-dotcms committed May 24, 2017
2 parents 80fc797 + 452e32a commit cd63f6a
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 74 deletions.
2 changes: 1 addition & 1 deletion dotCMS/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dotcmsReleaseVersion=4.1.0
dotcmsReleaseVersion=4.2.0
coreWebReleaseVersion=latest

tomcatInstallRepo=https://github.com/dotCMS/tomcat.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import com.dotcms.contenttype.model.field.ImmutableBinaryField;
import com.dotcms.contenttype.model.field.ImmutableDateTimeField;
import com.dotcms.contenttype.model.field.ImmutableFieldVariable;
import com.dotcms.contenttype.model.field.ImmutableSelectField;
import com.dotcms.contenttype.model.field.ImmutableTextAreaField;
import com.dotcms.contenttype.model.field.ImmutableTextField;
import com.dotcms.contenttype.model.field.SelectField;
import com.dotcms.contenttype.model.field.TextField;
import com.dotcms.contenttype.model.type.BaseContentType;
import com.dotcms.contenttype.model.type.ContentType;
Expand Down Expand Up @@ -156,6 +158,44 @@ public void testTextDBColumn() throws Exception {
assertThat("field2 text data type", field2.dataType() == DataTypes.TEXT);
assertThat("field2 text db column", field2.dbColumn().matches("text[0-9]+"));
}



@Test
public void testBadIntDBColumn() throws Exception {

String uu = UUID.randomUUID().toString();

TextField textField = ImmutableTextField.builder().name("test field" + uu)
.variable(TEST_VAR_PREFIX + uu).contentTypeId(Constants.NEWS).hint("my hint")
.dataType(DataTypes.INTEGER).dbColumn("bad1").build();

Field savedField = fieldFactory.save(textField);
String inode = savedField.inode();
Field field2 = fieldFactory.byId(inode);
assertThat("testBadIntDBColumn text data type", field2.dataType() == DataTypes.INTEGER);
assertThat("testBadIntDBColumn text db column", field2.dbColumn().matches("integer[0-9]+"));
}


@Test
public void testBadBoolDBColumn() throws Exception {

String uu = UUID.randomUUID().toString();

SelectField selectField = ImmutableSelectField.builder().name("test field" + uu)
.variable(TEST_VAR_PREFIX + uu).contentTypeId(Constants.NEWS).hint("my hint")
.dataType(DataTypes.BOOL).dbColumn("notreal").values("").build();

Field savedField = fieldFactory.save(selectField);
String inode = savedField.inode();
Field field2 = fieldFactory.byId(inode);
assertThat("testBadBoolDBColumn select data type", field2.dataType() == DataTypes.BOOL);
assertThat("testBadBoolDBColumn select db column", field2.dbColumn().matches("bool[0-9]+"));
}



@Test
public void testTextIntColumn() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private static void assertContentTypeUpdate(ContentType contentType) {

private static void assertResponse_OK(Response response){
assertNotNull(response);
assertEquals(response.getStatus(), 200);
assertEquals(200, response.getStatus());
assertNotNull(response.getEntity());
assertTrue(response.getEntity() instanceof ResponseEntityView);
assertTrue(
Expand All @@ -268,12 +268,12 @@ private static void assertResponse_OK(Response response){

private static void assertResponse_NOT_FOUND(Response response){
assertNotNull(response);
assertEquals(response.getStatus(), 404);
assertEquals(404, response.getStatus());
}

private static void assertResponse_BAD_REQUEST(Response response){
assertNotNull(response);
assertEquals(response.getStatus(), 400);
assertEquals(400, response.getStatus());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.dotcms.contenttype.model.field.TextField;
import com.dotcms.contenttype.model.field.TimeField;
import com.dotcms.contenttype.model.field.WysiwygField;
import com.dotcms.contenttype.model.type.BaseContentType;
import com.dotcms.contenttype.model.type.ContentType;
import com.dotcms.contenttype.model.type.ContentTypeBuilder;
import com.dotcms.contenttype.model.type.SimpleContentType;
Expand All @@ -64,18 +63,16 @@ public class FieldResourceTest {

private static final ObjectMapper mapper = new ObjectMapper();

private static final String typeName="fieldResourceTest " + UUIDUtil.uuid();
private static final String typeName="fieldResourceTest" + UUIDUtil.uuid();

@BeforeClass
public static void prepare() throws Exception{
IntegrationTestInitService.getInstance().init();



ContentType type = ContentTypeBuilder.builder(SimpleContentType.class).name(typeName).variable(typeName).build();
type = APILocator.getContentTypeAPI(APILocator.systemUser()).save(type);
Field field = FieldBuilder.builder(TextField.class).name("text").contentTypeId(type.id()).build();
APILocator.getContentTypeFieldAPI().save(field,APILocator.systemUser());

}


Expand Down Expand Up @@ -2349,7 +2346,7 @@ private void testField(AbstractFieldTester fieldTester) throws Exception {

private static void assertResponse_OK(Response response){
assertNotNull(response);
assertEquals(response.getStatus(), 200);
assertEquals(200, response.getStatus());
assertNotNull(response.getEntity());
assertTrue(response.getEntity() instanceof ResponseEntityView);
assertTrue(
Expand All @@ -2360,7 +2357,7 @@ private static void assertResponse_OK(Response response){

private static void assertResponse_NOT_FOUND(Response response){
assertNotNull(response);
assertEquals(response.getStatus(), 404);
assertEquals(404, response.getStatus());
assertNotNull(response.getEntity());
}

Expand All @@ -2378,13 +2375,8 @@ private static Field convertMapToField(Map<String, Object> fieldMap) {
}
}





private static ContentType getContentType() throws DotDataException, DotSecurityException {
User user = APILocator.getUserAPI().getSystemUser();
//return APILocator.getContentTypeAPI(user).search(" velocity_var_name = 'Testimonial'").get(0);
return APILocator.getContentTypeAPI(user).find(typeName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import javax.servlet.http.HttpServletRequest;

import com.dotcms.contenttype.model.field.Field;
import com.dotcms.contenttype.model.field.FieldBuilder;
import com.dotcms.contenttype.model.field.FieldVariable;
import com.dotcms.contenttype.model.field.TextField;
import com.dotcms.contenttype.model.type.ContentType;
import com.dotcms.contenttype.model.type.ContentTypeBuilder;
import com.dotcms.contenttype.model.type.SimpleContentType;
import com.dotcms.mock.request.MockAttributeRequest;
import com.dotcms.mock.request.MockHeaderRequest;
import com.dotcms.mock.request.MockHttpRequest;
Expand All @@ -23,6 +27,8 @@
import com.dotcms.util.IntegrationTestInitService;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.util.UUIDUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.liferay.portal.model.User;

Expand All @@ -33,10 +39,17 @@ public class FieldVariableResourceTest {

private static final ObjectMapper mapper = new ObjectMapper();

private static final String typeName="fieldVariableResourceTest" + UUIDUtil.uuid();
private static final String fieldName="name";

@BeforeClass
public static void prepare() throws Exception{
IntegrationTestInitService.getInstance().init();

ContentType type = ContentTypeBuilder.builder(SimpleContentType.class).name(typeName).variable(typeName).build();
type = APILocator.getContentTypeAPI(APILocator.systemUser()).save(type);
Field field = FieldBuilder.builder(TextField.class).name(fieldName).contentTypeId(type.id()).build();
APILocator.getContentTypeFieldAPI().save(field,APILocator.systemUser());
}


Expand Down Expand Up @@ -336,7 +349,7 @@ private static void assertFieldVariableUpdate(FieldVariable fieldVariable, Field

private static void assertResponse_OK(Response response){
assertNotNull(response);
assertEquals(response.getStatus(), 200);
assertEquals(200, response.getStatus());
assertNotNull(response.getEntity());
assertTrue(response.getEntity() instanceof ResponseEntityView);
assertTrue(
Expand All @@ -347,7 +360,7 @@ private static void assertResponse_OK(Response response){

private static void assertResponse_NOT_FOUND(Response response){
assertNotNull(response);
assertEquals(response.getStatus(), 404);
assertEquals(404, response.getStatus());
assertNotNull(response.getEntity());
}

Expand All @@ -363,15 +376,15 @@ private static FieldVariable convertMapToFieldVariable(Map<String, Object> field
}
}

private static ContentType getContentType() throws DotDataException {
private static ContentType getContentType() throws DotDataException, DotSecurityException {
User user = APILocator.getUserAPI().getSystemUser();

return APILocator.getContentTypeAPI(user).search(" velocity_var_name = 'Testimonial'").get(0);
return APILocator.getContentTypeAPI(user).find(typeName);
}

private static Field getField(ContentType contentType) throws DotDataException {

return APILocator.getContentTypeFieldAPI().byContentTypeAndVar(contentType, "name");
return APILocator.getContentTypeFieldAPI().byContentTypeAndVar(contentType, fieldName);
}

private static HttpServletRequest getHttpRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.CacheLocator;
import com.dotmarketing.business.DotStateException;
import com.dotmarketing.business.DotValidationException;
import com.dotmarketing.common.db.DotConnect;
import com.dotmarketing.db.LocalTransaction;
import com.dotmarketing.exception.DotDataException;
Expand Down Expand Up @@ -159,8 +160,8 @@ private Field normalizeData(final Field throwAwayField) throws DotDataException
FieldBuilder builder = FieldBuilder.builder(throwAwayField);
Field returnField = throwAwayField;

if("constant".equals(throwAwayField.dbColumn()) && !(throwAwayField instanceof ConstantField)) {
builder = ImmutableConstantField.builder().from(throwAwayField);
if("constant".equals(returnField.dbColumn()) && !(returnField instanceof ConstantField)) {
builder = ImmutableConstantField.builder().from(returnField);
builder.dbColumn(DataTypes.SYSTEM.value);
returnField = builder.build();
}
Expand All @@ -174,8 +175,13 @@ private Field normalizeData(final Field throwAwayField) throws DotDataException
builder.dbColumn(DataTypes.SYSTEM.value);
returnField = builder.build();
}
// if this is a new column assign a db column
if(returnField.dbColumn()==null){


// if this is a new column validate and assign a db column
try{
validateDbColumn(returnField);
}
catch(Throwable e){
builder.dbColumn(nextAvailableColumn(returnField));
returnField = builder.build();
}
Expand Down Expand Up @@ -225,6 +231,7 @@ private Field dbSaveUpdate(final Field throwAwayField) throws DotDataException {
builder.readOnly(oldField.readOnly());
builder.dataType(oldField.dataType());
builder.dbColumn(oldField.dbColumn());

} catch (NotFoundInDbException e) {
List<Field> fieldsAlreadyAdded = byContentTypeId(throwAwayField.contentTypeId());
// assign an inode and db column if needed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package com.dotmarketing.portlets.contentlet.ajax;

import static com.dotmarketing.business.PermissionAPI.PERMISSION_PUBLISH;
import static com.dotmarketing.business.PermissionAPI.PERMISSION_READ;
import static com.dotmarketing.business.PermissionAPI.PERMISSION_WRITE;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.dotcms.content.elasticsearch.util.ESUtils;
import com.dotcms.enterprise.FormAJAXProxy;
import com.dotcms.enterprise.LicenseUtil;
Expand All @@ -9,7 +27,6 @@
import com.dotmarketing.beans.Permission;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.CacheLocator;
import com.dotmarketing.business.DotCacheException;
import com.dotmarketing.business.DotStateException;
import com.dotmarketing.business.FactoryLocator;
import com.dotmarketing.business.PermissionAPI;
Expand Down Expand Up @@ -40,7 +57,6 @@
import com.dotmarketing.portlets.languagesmanager.model.LanguageKey;
import com.dotmarketing.portlets.structure.StructureUtil;
import com.dotmarketing.portlets.structure.factories.FieldFactory;

import com.dotmarketing.portlets.structure.model.Field;
import com.dotmarketing.portlets.structure.model.Field.FieldType;
import com.dotmarketing.portlets.structure.model.Relationship;
Expand All @@ -52,14 +68,14 @@
import com.dotmarketing.util.DateUtil;
import com.dotmarketing.util.InodeUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageRequestModeUtil;
import com.dotmarketing.util.PaginatedArrayList;
import com.dotmarketing.util.RegEX;
import com.dotmarketing.util.RegExMatch;
import com.dotmarketing.util.StringUtils;
import com.dotmarketing.util.UUIDGenerator;
import com.dotmarketing.util.UtilHTML;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.VelocityUtil;
import com.dotmarketing.util.WebKeys;
import com.dotmarketing.util.json.JSONArray;
import com.dotmarketing.util.json.JSONException;
Expand All @@ -72,24 +88,6 @@
import com.liferay.util.FileUtil;
import com.liferay.util.servlet.SessionMessages;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import static com.dotmarketing.business.PermissionAPI.PERMISSION_PUBLISH;
import static com.dotmarketing.business.PermissionAPI.PERMISSION_READ;
import static com.dotmarketing.business.PermissionAPI.PERMISSION_WRITE;

/**
* This class handles the communication between the view and the back-end
* service that returns information to the user regarding Contentlets in dotCMS.
Expand Down Expand Up @@ -1386,6 +1384,19 @@ public Map<String,Object> saveContent(List<String> formData, boolean isAutoSave,
if(contentlet.isHTMLPage()) {
HTMLPageAsset page = APILocator.getHTMLPageAssetAPI().fromContentlet(contentlet);
callbackData.put("htmlPageReferer", page.getURI() + "?" + WebKeys.HTMLPAGE_LANGUAGE + "=" + page.getLanguageId() + "&host_id=" + page.getHost());
HttpSession session = req.getSession();
boolean contentLocked = false;
boolean iCanLock = false;

try{
contentLocked = page.isLocked();
iCanLock = APILocator.getContentletAPI().canLock(contentlet, user);
}catch(DotLockException e){
iCanLock=false;
contentLocked = false;
}

PageRequestModeUtil.setBackEndModeInSession(req, contentLocked, iCanLock);
}

}
Expand Down
Loading

0 comments on commit cd63f6a

Please sign in to comment.