Skip to content

Commit

Permalink
Merge branch 'Issue-#1107' into Issue-#1426
Browse files Browse the repository at this point in the history
  • Loading branch information
oleh-maikovych committed May 13, 2020
2 parents 5cfeeb8 + 5cab7e5 commit 6fd4420
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import ua.com.fielden.platform.entity.annotation.Observable;
import ua.com.fielden.platform.entity.annotation.Title;

/**
* Entity that provides information about master to open.
*
* @author TG Team
*
*/
@KeyType(String.class)
@KeyTitle("Element Name")
@DescTitle("Element URI")
Expand All @@ -28,7 +34,7 @@ public class MasterInfo extends AbstractEntity<String> {
private String widthUnit;

@IsProperty
@Title(value = "Height Unit", desc = "Desc")
@Title(value = "Height Unit")
private String heightUnit;

@IsProperty
Expand All @@ -48,13 +54,9 @@ public class MasterInfo extends AbstractEntity<String> {
private String requireMasterEntity;

@IsProperty
@Title(value = "Entity Type", desc = "Desc")
@Title(value = "Entity Type")
private String entityType;

@IsProperty
@Title(value = "Entity Id", desc = "Desc")
private Long entityId;

@IsProperty
@Title(value = "Short Description", desc = "Action's short description")
private String shortDesc;
Expand All @@ -63,16 +65,6 @@ public class MasterInfo extends AbstractEntity<String> {
@Title(value = "Long Description", desc = "Action's long description")
private String longDesc;

@Observable
public MasterInfo setEntityId(final Long entityId) {
this.entityId = entityId;
return this;
}

public Long getEntityId() {
return entityId;
}

@Observable
public MasterInfo setEntityType(final String entityType) {
this.entityType = entityType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public final Restlet createInboundRoot() {
router.attach("/test/egi", new EgiExampleResourceFactory(injector));

//Attache master retrieve resources
router.attach("/master/{entityType}/{entityId}", new MasterInfoProviderResourceFactory(webApp, deviceProvider, dates, restUtil));
router.attach("/master/{entityType}", new MasterInfoProviderResourceFactory(webApp, deviceProvider, dates, restUtil));

// Registering entity centres:
attachCentreResources(router, webApp, restUtil);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.lang.String.format;
import static org.restlet.data.MediaType.APPLICATION_JSON;
import static ua.com.fielden.platform.error.Result.failure;
import static ua.com.fielden.platform.error.Result.failuref;
import static ua.com.fielden.platform.error.Result.successful;
import static ua.com.fielden.platform.serialisation.api.SerialiserEngines.JACKSON;

Expand Down Expand Up @@ -374,9 +375,9 @@ public <T extends AbstractEntity<?>> Representation singleJsonMasterRepresentati
if (entity != null) {
// valid and invalid entities: both kinds are represented using successful result. Use client-side isValid() method
// in 'tg-reflector' to differentiate them
result = new Result(entity, "OK");
result = successful(entity);
} else {
result = new Result(null, new Exception(format("Could not find master for entity type: %s.", entityType)));
result = failuref("Could not find master for entity type: %s.", entityType);
}
final byte[] bytes = serialiser.serialise(result, SerialiserEngines.JACKSON);
return encodedRepresentation(new ByteArrayInputStream(bytes), MediaType.APPLICATION_JSON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
import org.restlet.resource.Get;

import ua.com.fielden.platform.entity.AbstractEntity;
import ua.com.fielden.platform.master.MasterInfo;
import ua.com.fielden.platform.utils.IDates;
import ua.com.fielden.platform.web.interfaces.IDeviceProvider;
import ua.com.fielden.platform.web.resources.RestServerUtil;
import ua.com.fielden.platform.web.resources.webui.exceptions.MissingEntityType;
import ua.com.fielden.platform.web.resources.webui.exceptions.MissingEntityTypeException;
import ua.com.fielden.platform.web.view.master.MasterInfoProvider;

/**
* Web resource for that gets the {@link MasterInfo}
*
* @author TG Team
*
*/
public class MasterInfoProviderResource extends AbstractWebResource {

private final MasterInfoProvider masterInfoProvider;
Expand All @@ -29,20 +36,21 @@ public MasterInfoProviderResource(final MasterInfoProvider masterInfoProvider, f
@Get
@Override
public Representation get() {
return handleUndesiredExceptions(getResponse(), () -> restUtil.singleJsonMasterRepresentation(masterInfoProvider.getMasterInfo(getEntityType(), getEntityId()), getRequest().getAttributes().get("entityType").toString()), restUtil);
}

private Long getEntityId() {
return Long.valueOf(getRequest().getAttributes().get("entityId").toString());
return handleUndesiredExceptions(getResponse(), () -> restUtil.singleJsonMasterRepresentation(masterInfoProvider.getMasterInfo(getEntityType()), getRequest().getAttributes().get("entityType").toString()), restUtil);
}

/**
* Returns the entity type as class. If entity type attribute of URI can not be converted to class {@link MissingEntityTypeException} exception will be thrown.
*
* @return
*/
@SuppressWarnings("unchecked")
private Class<? extends AbstractEntity<?>> getEntityType() {
final String entityType = getRequest().getAttributes().get("entityType").toString();
try {
return (Class<? extends AbstractEntity<?>>) Class.forName(entityType);
} catch (final ClassNotFoundException e) {
throw new MissingEntityType(String.format("The entity type class is missing for type: %s", entityType), e);
throw new MissingEntityTypeException(String.format("The entity type class is missing for type: %s", entityType), e);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ua.com.fielden.platform.web.resources.webui.exceptions;

import ua.com.fielden.platform.web.resources.webui.MasterInfoProviderResource;

/**
* The {@link RuntimeException} that is thrown when {@link MasterInfoProviderResource} can't find the type of entity for which master info was requested
*
* @author TG Team
*
*/
public class MissingEntityTypeException extends RuntimeException {
private static final long serialVersionUID = 1L;

/**
* Constructs {@link MissingEntityTypeException} with custom message.
*
* @param msg
*/
public MissingEntityTypeException(final String msg) {
super(msg);
}

/**
* Constructs {@link MissingEntityTypeException} with custom message and additional {@link Throwable} cause.
*
* @param msg
* @param cause
*/
public MissingEntityTypeException(final String msg, final Throwable cause) {
super(msg, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1797,13 +1797,13 @@ public JsCode build() {
.also()
.addEditableProp("entityProp").asAutocompleter().withMatcher(ContextMatcher.class).minWidth(40)
.withAction(editAction().withContext(context().withCurrentEntity().withSelectionCrit().build())
.preAction(new EntityNavigationPreAction("Cool entity"))
.icon("editor:mode-edit")
.withStyle("color: green")
.shortDesc("Edit entity")
.longDesc("Opens master for editing this entity")
.withNoParentCentreRefresh()
.build())
.preAction(new EntityNavigationPreAction("Cool entity"))
.icon("editor:mode-edit")
.withStyle("color: green")
.shortDesc("Edit entity")
.longDesc("Opens master for editing this entity")
.withNoParentCentreRefresh()
.build())
.also()
.addEditableProp("booleanProp").minWidth(49)
.also()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public class EntityNavigationPreAction implements IPreAction {

private final String navigationType;

/**
* Creates pre-action for action that allows to navigate to another entity without closing dialog, such action can work only on EGI.
*
* @param navigationType - type description that is used to inform user what type of entity is currently opened and is navigating.
*/
public EntityNavigationPreAction(final String navigationType) {
this.navigationType = navigationType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ public MasterInfoProvider(final IWebUiConfig webUiConfig) {
this.webUiConfig = webUiConfig;
}

public MasterInfo getMasterInfo(final Class<? extends AbstractEntity<?>> type, final Long entityId) {
public MasterInfo getMasterInfo(final Class<? extends AbstractEntity<?>> type) {
try {
return webUiConfig.configApp().getOpenMasterAction(type).get().map(entityActionConfig -> {
final FunctionalActionElement funcElem = new FunctionalActionElement(entityActionConfig, 0, FunctionalActionKind.PRIMARY_RESULT_SET);
final DomElement actionElement = funcElem.render();
final MasterInfo info = new MasterInfo();
info.setEntityId(entityId);
info.setKey(actionElement.getAttr("element-name").value.toString());
info.setDesc(actionElement.getAttr("component-uri").value.toString());
info.setShortDesc(actionElement.getAttr("short-desc").value.toString());
Expand All @@ -43,17 +42,16 @@ public MasterInfo getMasterInfo(final Class<? extends AbstractEntity<?>> type, f
info.setHeightUnit(prefDim.heightUnit.value);
});
return info;
}).orElse(buildDefaultMasterConfiguration(type, entityId));
}).orElse(buildDefaultMasterConfiguration(type));
} catch (final WebUiBuilderException e) {
return buildDefaultMasterConfiguration(type, entityId);
return buildDefaultMasterConfiguration(type);
}
}

private MasterInfo buildDefaultMasterConfiguration(final Class<? extends AbstractEntity<?>> type, final Long entityId) {
private MasterInfo buildDefaultMasterConfiguration(final Class<? extends AbstractEntity<?>> type) {
return webUiConfig.configApp().getMaster(type).map(master -> {
final String entityTitle = TitlesDescsGetter.getEntityTitleAndDesc(type).getKey();
final MasterInfo info = new MasterInfo();
info.setEntityId(entityId);
info.setKey("tg-EntityEditAction-master");
info.setDesc("/master_ui/ua.com.fielden.platform.entity.EntityEditAction");
info.setShortDesc(format("Edit %s", entityTitle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { tearDownEvent } from '/resources/reflection/tg-polymer-utils.js';
import { TgReflector } from '/app/tg-reflector.js';
import { TgSerialiser } from '/resources/serialisation/tg-serialiser.js';
import { _timeZoneHeader } from '/resources/reflection/tg-date-utils.js';
import {processResponseError, toastMsgForError} from '/resources/reflection/tg-ajax-utils.js';

const template = html`
<style>
Expand Down Expand Up @@ -479,29 +480,34 @@ Polymer({

self.persistActiveElement();

const currentEntityType = this._calculateCurrentEntityType();
if (this.dynamicAction && this.currentEntity && this._previousEntityType !== currentEntityType) {
if (!this.elementName) {//Element name for dynamic action is not specified at first run
this._originalShortDesc = this.shortDesc;//It means that sjortDesc wasn't changed yet.
}
this._masterUri = '/master/' + currentEntityType + '/' + this.currentEntity.get("id");
this.isActionInProgress = true;
this.$.masterRetriever.generateRequest().completes
.then(res => {
try {
this._processMasterRetriever(res);
this._previousEntityType = currentEntityType;
postMasterInfoRetrieve();
}catch (e) {

if (this.dynamicAction && this.currentEntity) {
const currentEntityType = this._calculateCurrentEntityType();
if (this._previousEntityType !== currentEntityType) {
if (!this.elementName) {//Element name for dynamic action is not specified at first run
this._originalShortDesc = this.shortDesc;//It means that shortDesc wasn't changed yet.
}
this._masterUri = '/master/' + currentEntityType;
this.isActionInProgress = true;
this.$.masterRetriever.generateRequest().completes
.then(res => {
try {
this._processMasterRetriever(res);
this._previousEntityType = currentEntityType;
postMasterInfoRetrieve();
}catch (e) {
this.isActionInProgress = false;
this.restoreActionState();
console.log("The action was rejected with error: " + e);
}
}).catch(error => {
this.isActionInProgress = false;
this.restoreActionState();
console.log("The action was rejected with error: " + error);
}
}).catch(error => {
this.isActionInProgress = false;
this.restoreActionState();
console.log("The action was rejected with error: " + error);
});
});
} else {
postMasterInfoRetrieve();
}
} else {
postMasterInfoRetrieve();
}
Expand Down Expand Up @@ -738,7 +744,7 @@ Polymer({

if (this._reflector.isError(deserialisedResult)) {
console.log('deserialisedResult: ', deserialisedResult);
this.toaster && this.toaster.openToastForError(deserialisedResult.message, this._toastMsgForError(deserialisedResult), true);
this.toaster && this.toaster.openToastForError(deserialisedResult.message, toastMsgForError(this._reflector, deserialisedResult), true);
throw {msg: deserialisedResult};
}
const masterInfo = deserialisedResult.instance;
Expand All @@ -748,7 +754,6 @@ Polymer({
this.longDesc = this.longDesc || masterInfo.longDesc;
this.attrs = Object.assign({}, this.attrs, {
entityType: masterInfo.entityType,
entityId: masterInfo.entityId,
currentState:'EDIT',
prefDim: masterInfo.width && masterInfo.height && masterInfo.widthUnit && masterInfo.heightUnit && {
width: () => masterInfo.width,
Expand All @@ -768,30 +773,7 @@ Polymer({
},

_processMasterError: function (e) {
console.log('PROCESS ERROR', e.error);
const xhr = e.detail.request.xhr;
if (xhr.status === 500) { // internal server error, which could either be due to business rules or have some other cause due to a bug or db connectivity issue
const deserialisedResult = this._serialiser.deserialise(xhr.response);

if (this._reflector.isError(deserialisedResult)) {
// throw the toast message about the server-side error
this.toaster && this.toaster.openToastForError(this._reflector.exceptionMessage(deserialisedResult.ex), this._toastMsgForError(deserialisedResult), true);
} else {
//throw new Error('Responses with status code 500 suppose to carry an error cause!');
this.toaster && this.toaster.openToastForError('Master load error: ', 'Responses with status code 500 suppose to carry an error cause!', true);
}
} else if (xhr.status === 403) { // forbidden!
this.toaster && this.toaster.openToastForError('Access denied.', 'The current session has expired. Please login and try again.', true);
} else if (xhr.status === 503) { // service unavailable
this.toaster && this.toaster.openToastForError('Service Unavailable.', 'Server responded with error 503 (Service Unavailable).', true);
} else if (xhr.status >= 400) { // other client or server error codes
this.toaster && this.toaster.openToastForError('Service Error (' + xhr.status + ').', 'Server responded with error code ' + xhr.status, true);
} else { // for other codes just log the code
console.warn('Server responded with error code ', xhr.status);
}
processResponseError(e, this._reflector, this._serialiser, null, this.toaster);
},

_toastMsgForError: function (errorResult) {
return this._reflector.stackTrace(errorResult.ex);
},
});
Loading

0 comments on commit 6fd4420

Please sign in to comment.