Skip to content

Commit

Permalink
MID-2664 is not finished yet
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Nov 16, 2015
1 parent 2c496b0 commit 6337f1e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
Expand Up @@ -19,7 +19,8 @@
<wicket:panel>
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<!-- todo image -->
<img src="img/placeholder.png" class="user-image" alt="User Image"/>
<div wicket:id="summaryIconBox" class="user-image"><span class="user-thumbnail-helper"/><span wicket:id="summaryIcon"/><img wicket:id="summaryPhoto" class="user-thumbnail"/></div>
<!--<img src="img/placeholder.png" class="user-image" alt="User Image"/>-->
<span class="hidden-xs" wicket:id="usernameLink"/>
</a>
<ul class="dropdown-menu">
Expand Down
Expand Up @@ -19,6 +19,9 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.crypto.EncryptionException;
import com.evolveum.midpoint.prism.crypto.Protector;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.RetrieveOption;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.task.api.Task;
Expand All @@ -28,6 +31,7 @@
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.util.BaseSimplePanel;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.page.admin.home.PageMyPasswordQuestions;
import com.evolveum.midpoint.web.page.admin.home.dto.PasswordQuestionsDto;
Expand All @@ -37,17 +41,22 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionsCredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.resource.AbstractResource;
import org.apache.wicket.request.resource.ByteArrayResource;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

Expand All @@ -59,20 +68,29 @@ public class UserMenuPanel extends BaseSimplePanel {
private static final Trace LOGGER = TraceManager.getTrace(UserMenuPanel.class);
private static final String ID_USERNAME_LINK = "usernameLink";
private static final String ID_LOGOUT_LINK = "logoutLink";
private static final String ID_ICON_BOX = "summaryIconBox";

private static final String ID_USERNAME = "username";

private static final String ID_EDIT_PROFILE = "editProfile";
private static final String ID_PASSWORD_QUESTIONS = "passwordQuestions";
private IModel<PasswordQuestionsDto> passwordQuestionsDtoIModel;
// private PrismObject<UserType> userModel;
private Model<PrismObject<UserType>> userModel = new Model<PrismObject<UserType>>();
private static final String DOT_CLASS = UserMenuPanel.class.getName() + ".";
private static final String OPERATION_LOAD_USER = DOT_CLASS + "loaduser";
private static final String ID_PHOTO = "summaryPhoto";
private static final String ID_ICON = "summaryIcon";

private boolean isModelLoaded = false;
private boolean isUserModelLoaded = false;
private boolean isPasswordModelLoaded = false;

public UserMenuPanel(String id) {
super(id);
if (!isModelLoaded) {
// if (!isUserModelLoaded) {
// loadModel();
// }
if (!isPasswordModelLoaded) {
passwordQuestionsDtoIModel = new LoadableModel<PasswordQuestionsDto>(false) {

private static final long serialVersionUID = 1L;
Expand All @@ -82,11 +100,70 @@ protected PasswordQuestionsDto load() {
return loadModel();
}
};
// isPasswordModelLoaded = true;
}
}

@Override
protected void initLayout() {
WebMarkupContainer iconBox = new WebMarkupContainer(ID_ICON_BOX);
add(iconBox);

Image img = new Image(ID_PHOTO, new AbstractReadOnlyModel<AbstractResource>() {

@Override
public AbstractResource getObject() {
byte[] jpegPhoto = userModel.getObject().asObjectable().getJpegPhoto();
if(jpegPhoto == null) {
return null;
} else {
return new ByteArrayResource("image/jpeg",jpegPhoto);
}
}
});
img.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
byte [] photo = null;
if (userModel != null && userModel.getObject() == null){
loadModel();
photo = userModel.getObject().asObjectable().getJpegPhoto();
if (photo != null){

}
}
if (userModel != null && userModel.getObject() != null){
photo = userModel.getObject().asObjectable().getJpegPhoto();
if (photo != null){

}
}
return userModel == null ? false :
(userModel.getObject() == null ? false : photo != null);
}
});
iconBox.add(img);

Label icon = new Label(ID_ICON,"");
icon.add(new AttributeModifier("class", "fa fa-user"));
icon.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
if (userModel != null && userModel.getObject() == null){
loadModel();
}
return userModel == null ? false :
(userModel.getObject() == null ? false : userModel.getObject().asObjectable().getJpegPhoto() == null);


}
});
iconBox.add(icon);





Label usernameLink = new Label(ID_USERNAME_LINK, new AbstractReadOnlyModel<String>() {

@Override
Expand Down Expand Up @@ -123,7 +200,11 @@ public void onClick(AjaxRequestTarget target) {
};
add(editPasswordQ);

if (!isModelLoaded) {
if (!isUserModelLoaded) {
loadModel();

}
if (!isPasswordModelLoaded ){
passwordQuestionsDtoIModel = new LoadableModel<PasswordQuestionsDto>(false) {

private static final long serialVersionUID = 1L;
Expand All @@ -133,14 +214,16 @@ protected PasswordQuestionsDto load() {
return loadModel();
}
};
isPasswordModelLoaded = true;
}
if (passwordQuestionsDtoIModel.getObject() == null ||
if (passwordQuestionsDtoIModel != null &&
(passwordQuestionsDtoIModel.getObject() == null ||
((passwordQuestionsDtoIModel.getObject().getPwdQuestion() == null
|| passwordQuestionsDtoIModel.getObject().getPwdQuestion().trim().equals(""))
&& (passwordQuestionsDtoIModel.getObject().getSecurityAnswers() == null
|| passwordQuestionsDtoIModel.getObject().getSecurityAnswers().size() == 0)
&& (passwordQuestionsDtoIModel.getObject().getPwdAnswer() == null
|| passwordQuestionsDtoIModel.getObject().getPwdAnswer().trim().equals("")))) {
|| passwordQuestionsDtoIModel.getObject().getPwdAnswer().trim().equals(""))))) {
editPasswordQ.setVisible(false);
}
}
Expand Down Expand Up @@ -173,7 +256,10 @@ private PasswordQuestionsDto loadModel() {
Task task = ((PageBase)getPage()).createSimpleTask(OPERATION_LOAD_USER);
OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);

PrismObject<UserType> user = ((PageBase)getPage()).getModelService().getObject(UserType.class, userOid, null, task, subResult);
Collection options = SelectorOptions.createCollection(UserType.F_JPEG_PHOTO,
GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
PrismObject<UserType> user = ((PageBase)getPage()).getModelService().getObject(UserType.class, userOid, options, task, subResult);
userModel.setObject(user);

dto.setSecurityAnswers(createUsersSecurityQuestionsList(user));

Expand All @@ -185,7 +271,7 @@ private PasswordQuestionsDto loadModel() {

} finally {
result.recomputeStatus();
isModelLoaded = true;
isUserModelLoaded = true;
}
return dto;
}
Expand Down

0 comments on commit 6337f1e

Please sign in to comment.